﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.DB.Electrical;
using Autodesk.Revit.DB.ExtensibleStorage;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.UI;
using YArchitech.Controls;
using YArchitech.LIB;
using YArchitech.Revit.RevitExtension;

namespace YArchitech.Revit
{
	public class YJKRevitTools
	{
		public static void WritePipingLocationCurve(Element elem, XYZ xyzStart, XYZ xyzEnd)
		{
			if (elem.Location is LocationCurve)
			{
				LocationCurve locationCurve = elem.Location as LocationCurve;
				Line curve = YJKLineEx.YJKGetBound(xyzStart, xyzEnd);
				locationCurve.Curve = curve;
			}
		}

		public static XYZ getLocationCurveDirectionfarAwayfromXYZ(Element elem, XYZ xyz)
		{
			XYZ xyz2 = null;
			if (elem.Location is LocationCurve)
			{
				Line curve = (elem.Location as LocationCurve).Curve as Line;
				XYZ hyendPoint = curve.GetEndPoint(0);
				XYZ hyendPoint2 = curve.GetEndPoint(1);
				xyz2 = ((curve.GetEndPoint(0).DistanceTo(xyz) > curve.GetEndPoint(1).DistanceTo(xyz)) ? (hyendPoint - hyendPoint2) : (hyendPoint2 - hyendPoint));
			}
			return xyz2.Normalize();
		}

		public static XYZ GetFaceProject(XYZ p, XYZ faceOrigin, XYZ faceXVec, XYZ faceYVec, XYZ faceNormal)
		{
			double num = (faceNormal.X * faceNormal.Y * faceOrigin.Y + faceNormal.Y * faceNormal.Y * p.X - faceNormal.X * faceNormal.Y * p.Y + faceNormal.X * faceNormal.Z * faceOrigin.Z + faceNormal.Z * faceNormal.Z * p.X - faceNormal.X * faceNormal.Z * p.Z + faceNormal.X * faceNormal.X * faceOrigin.X) / (faceNormal.X * faceNormal.X + faceNormal.Y * faceNormal.Y + faceNormal.Z * faceNormal.Z);
			double num2 = (faceNormal.Y * faceNormal.Z * faceOrigin.Z + faceNormal.Z * faceNormal.Z * p.Y - faceNormal.Y * faceNormal.Z * p.Z + faceNormal.Y * faceNormal.X * faceOrigin.X + faceNormal.X * faceNormal.X * p.Y - faceNormal.X * faceNormal.Y * p.X + faceNormal.Y * faceNormal.Y * faceOrigin.Y) / (faceNormal.X * faceNormal.X + faceNormal.Y * faceNormal.Y + faceNormal.Z * faceNormal.Z);
			double num3 = (faceNormal.X * faceOrigin.X * faceNormal.Z + faceNormal.X * faceNormal.X * p.Z - faceNormal.X * p.X * faceNormal.Z + faceNormal.Y * faceOrigin.Y * faceNormal.Z + faceNormal.Y * faceNormal.Y * p.Z - faceNormal.Y * p.Y * faceNormal.Z + faceNormal.Z * faceNormal.Z * faceOrigin.Z) / (faceNormal.X * faceNormal.X + faceNormal.Y * faceNormal.Y + faceNormal.Z * faceNormal.Z);
			return new XYZ(num, num2, num3);
		}

		public static List<Parameter> GetSpecificDuctParameter(Duct duct, XYZ vector)
		{
			List<Parameter> list = null;
			IEnumerable<Edge> ductEdges = UnifiedModified.GetDuctEdges(duct);
			Edge edge = null;
			foreach (Edge edge2 in ductEdges)
			{
				XYZ xyz = edge2.Tessellate()[0];
				XYZ xyz2 = edge2.Tessellate()[1].Subtract(xyz).Normalize();
				if (xyz2.IsAlmostEqualTo(vector, 0.01) || xyz2.IsAlmostEqualTo(-1.0 * vector, 0.01))
				{
					edge = edge2;
					break;
				}
			}
			double approximateLength = edge.ApproximateLength;
			Parameter parameter = duct.get_Parameter(BuiltInParameter.RBS_CURVE_WIDTH_PARAM);
			Parameter item = duct.get_Parameter(BuiltInParameter.RBS_CURVE_HEIGHT_PARAM);
			if (Math.Abs(parameter.AsDouble() - approximateLength) < 0.00984251968503937)
			{
				list.Add(parameter);
				list.Add(item);
			}
			else
			{
				list.Add(item);
				list.Add(parameter);
			}
			return list;
		}

		public static FamilySymbol GetFamilySymbolByName(string FolderName, string fsName, Autodesk.Revit.DB.Document doc, ref string loadMSG)
		{
			FamilySymbol familySymbol = null;
			if (string.IsNullOrEmpty(fsName))
			{
				loadMSG = "族名不能为空！";
				return familySymbol;
			}
			familySymbol = YJKRevitTools.GetFamilySymbol(fsName, doc);
			if (familySymbol == null)
			{
				string text = Path.Combine(Product.FamilyLocation, RevitVersion.Version, FolderName, fsName + ".rfa");
				if (!File.Exists(text))
				{
					loadMSG = "族不存在或者加载地址不正确！";
					return familySymbol;
				}
				SubTransaction subTransaction = new SubTransaction(doc);
				subTransaction.Start();
				Family family = null;
				doc.LoadFamily(text, out family);
				if (family == null)
				{
					subTransaction.RollBack();
					return null;
				}
				familySymbol = YJKRevitTools.GetFamilySymbol(fsName, doc);
				subTransaction.Commit();
			}
			return familySymbol;
		}

		public static FamilySymbol GetMarkTagSymbolByName(string folderName, string familyName, string fsName, Autodesk.Revit.DB.Document doc, ref string loadMSG, BuiltInCategory builtInCategory)
		{
			FamilySymbol familySymbol = null;
			if (string.IsNullOrEmpty(familyName))
			{
				loadMSG = "族名称不能为空！";
				return familySymbol;
			}
			if (string.IsNullOrEmpty(fsName))
			{
				loadMSG = "族类型名称不能为空！";
				return familySymbol;
			}
			familySymbol = YJKRevitTools.GetFamilySymbol(familyName + ".rfa", fsName, doc, builtInCategory);
			if (familySymbol != null)
			{
				return familySymbol;
			}
			SubTransaction subTransaction = new SubTransaction(doc);
			try
			{
				string text = Path.Combine(Product.FamilyLocation, RevitVersion.Version, folderName, familyName + ".rfa");
				if (!File.Exists(text))
				{
					loadMSG = "族不存在或者加载地址不正确！";
					return familySymbol;
				}
				subTransaction.Start();
				Family family = null;
				doc.LoadFamily(text, out family);
				if (family == null)
				{
					subTransaction.RollBack();
					return null;
				}
				familySymbol = YJKRevitTools.GetFamilySymbol(familyName + ".rfa", fsName, doc, builtInCategory);
				subTransaction.Commit();
			}
			catch (Exception ex)
			{
				ex.ToString();
				if (subTransaction != null && subTransaction.GetStatus() == 1)
				{
					subTransaction.RollBack();
				}
				return familySymbol;
			}
			return familySymbol;
		}

		public static Family GetFamilyByName(string familyName, Autodesk.Revit.DB.Document doc, BuiltInCategory builtInCategory)
		{
			Family result = null;
			List<Element> elementByCategory = YJKElementFilter.GetElementByCategory(doc, typeof(FamilySymbol), builtInCategory);
			if (elementByCategory == null || elementByCategory.Count < 1)
			{
				return null;
			}
			foreach (Element element in elementByCategory)
			{
				FamilySymbol familySymbol = element as FamilySymbol;
				if (familySymbol != null && familySymbol.Family.Name == familyName)
				{
					result = familySymbol.Family;
					break;
				}
			}
			return result;
		}

		public static FamilySymbol GetFamilySymbolByName(string filePath, string fsName, Autodesk.Revit.DB.Document doc, BuiltInCategory builtInCategory)
		{
			FamilySymbol familySymbol = null;
			if (string.IsNullOrEmpty(fsName))
			{
				return familySymbol;
			}
			familySymbol = YJKRevitTools.GetFamilySymbol(filePath.Split(new char[]
			{
				'\\'
			}).Last<string>(), fsName, doc, builtInCategory);
			if (familySymbol == null)
			{
				if (!File.Exists(filePath))
				{
					return familySymbol;
				}
				SubTransaction subTransaction = new SubTransaction(doc);
				subTransaction.Start();
				Family family = null;
				doc.LoadFamily(filePath, out family);
				if (family == null)
				{
					subTransaction.RollBack();
					return null;
				}
				familySymbol = YJKRevitTools.GetFamilySymbol(filePath.Split(new char[]
				{
					'\\'
				}).Last<string>(), fsName, doc, builtInCategory);
				subTransaction.Commit();
			}
			return familySymbol;
		}

		public static List<Pipe> judgeWhitchPipeIsHigh(List<Pipe> list)
		{
			List<Pipe> list2 = new List<Pipe>();
			double num = (list.ElementAt(0).Location as LocationCurve).Curve.GetEndPoint(0).Z + (list.ElementAt(0).Location as LocationCurve).Curve.GetEndPoint(1).Z;
			double num2 = (list.ElementAt(1).Location as LocationCurve).Curve.GetEndPoint(0).Z + (list.ElementAt(1).Location as LocationCurve).Curve.GetEndPoint(1).Z;
			Pipe item = (num - num2 >= 1E-07) ? list.ElementAt(0) : list.ElementAt(1);
			Pipe item2 = (num - num2 < 1E-07) ? list.ElementAt(0) : list.ElementAt(1);
			list2.Add(item);
			list2.Add(item2);
			return list2;
		}

		public static LinePatternElement CreateLinePatternElement(string patternName, Autodesk.Revit.DB.Document doc, bool isZiPen)
		{
			List<LinePatternSegment> list = new List<LinePatternSegment>();
			list.Add(new LinePatternSegment((LinePatternSegmentType)2, 0.0));
			list.Add(new LinePatternSegment((LinePatternSegmentType)1, 0.02));
			list.Add(new LinePatternSegment((LinePatternSegmentType)0, 0.03));
			list.Add(new LinePatternSegment((LinePatternSegmentType)1, 0.02));
			LinePattern linePattern = new LinePattern(patternName);
			linePattern.SetSegments(list);
			return LinePatternElement.Create(doc, linePattern);
		}

		public static bool BeSlopePipe(Pipe pipe)
		{
			return pipe.get_Parameter(BuiltInParameter.RBS_PIPE_SLOPE).AsDouble() != 0.0;
		}

		public static Connector SeparatePipeEndPoint(Pipe pipe)
		{
			ConnectorManager connectorManager = pipe.ConnectorManager;
			Connector connector = null;
			int num = 0;
			foreach (object obj in connectorManager.Connectors)
			{
				Connector connector2 = (Connector)obj;
				if (connector2.IsConnected)
				{
					num++;
					connector = connector2;
				}
			}
			if (num == 1)
			{
				Connector connectConnector = YJKRevitTools.GetConnectConnector(connector);
				connector.DisconnectFrom(connectConnector);
				return connectConnector;
			}
			return null;
		}

		public static LinePatternElement CreateLinePatternElement(string patternName, Autodesk.Revit.DB.Document doc)
		{
			List<LinePatternSegment> list = new List<LinePatternSegment>();
			list.Add(new LinePatternSegment((LinePatternSegmentType)2, 0.0));
			list.Add(new LinePatternSegment((LinePatternSegmentType)1, 0.02));
			list.Add(new LinePatternSegment((LinePatternSegmentType)0, 0.03));
			list.Add(new LinePatternSegment((LinePatternSegmentType)1, 0.02));
			LinePattern linePattern = new LinePattern(patternName);
			linePattern.SetSegments(list);
			return LinePatternElement.Create(doc, linePattern);
		}

		public static List<LinePatternElement> Get_LinePatternElement(Autodesk.Revit.DB.Document document)
		{
			IEnumerable<Element> enumerable = new FilteredElementCollector(document).OfClass(typeof(LinePatternElement)).ToElements();
			List<LinePatternElement> list = new List<LinePatternElement>();
			foreach (Element element in enumerable)
			{
				LinePatternElement item = element as LinePatternElement;
				list.Add(item);
			}
			return list;
		}

		public static int judgeTwoDuctAlignmentModel(Duct duct1, Duct duct2)
		{
			int result = 0;
			Line line = (duct1.Location as LocationCurve).Curve as Line;
			Line line2 = (duct2.Location as LocationCurve).Curve as Line;
			XYZ hyendPoint = line.GetEndPoint(0);
			XYZ hyendPoint2 = line2.GetEndPoint(0);
			double z = hyendPoint.Z;
			double z2 = hyendPoint2.Z;
			double ductHeight = YJKRevitTools.getDuctHeight(duct1);
			double ductWidth = YJKRevitTools.getDuctWidth(duct1);
			double ductHeight2 = YJKRevitTools.getDuctHeight(duct2);
			double ductWidth2 = YJKRevitTools.getDuctWidth(duct2);
			double num = (ductWidth > ductWidth2) ? ductWidth2 : ductWidth;
			double num2 = (ductWidth < ductWidth2) ? ductWidth2 : ductWidth;
			double num3 = (ductHeight > ductHeight2) ? ductHeight2 : ductHeight;
			double num4 = (ductHeight < ductHeight2) ? ductHeight2 : ductHeight;
			YJKLine hyline = new YJKLine(line);
			if (Math.Abs(z - z2) < 1E-06)
			{
				if (hyline.IsParallel(line2))
				{
					if (hyline.GetDistance(line2) < 0.0001)
					{
						result = 1;
					}
					else if (Math.Abs(num / 2.0 + hyline.GetDistance(line2) - num2 / 2.0) < 0.0001)
					{
						result = 2;
					}
				}
				else if (Math.Abs(z - z2) < 0.0001)
				{
					result = 9;
				}
			}
			else if (hyline.IsParallel(line2))
			{
				if (Math.Abs(num / 2.0 + Math.Sqrt(hyline.GetDistance(line2) * hyline.GetDistance(line2) - Math.Abs(z - z2) * Math.Abs(z - z2)) - num2 / 2.0) < 0.0001)
				{
					if (Math.Abs(num3 / 2.0 + Math.Abs(z - z2) - num4 / 2.0) < 0.0001)
					{
						if ((z < z2 && YJKRevitTools.getDuctHeight(duct1) > YJKRevitTools.getDuctHeight(duct2)) || (z > z2 && YJKRevitTools.getDuctHeight(duct1) < YJKRevitTools.getDuctHeight(duct2)))
						{
							result = 3;
						}
						else if ((z < z2 && YJKRevitTools.getDuctHeight(duct1) < YJKRevitTools.getDuctHeight(duct2)) || (z > z2 && YJKRevitTools.getDuctHeight(duct1) > YJKRevitTools.getDuctHeight(duct2)))
						{
							result = 4;
						}
					}
					else
					{
						result = 2;
					}
				}
				else if (Math.Abs(num3 / 2.0 + Math.Abs(z - z2) - num4 / 2.0) < 0.0001)
				{
					if ((z < z2 && YJKRevitTools.getDuctHeight(duct1) > YJKRevitTools.getDuctHeight(duct2)) || (z > z2 && YJKRevitTools.getDuctHeight(duct1) < YJKRevitTools.getDuctHeight(duct2)))
					{
						result = 5;
					}
					else if ((z < z2 && YJKRevitTools.getDuctHeight(duct1) < YJKRevitTools.getDuctHeight(duct2)) || (z > z2 && YJKRevitTools.getDuctHeight(duct1) > YJKRevitTools.getDuctHeight(duct2)))
					{
						result = 6;
					}
				}
			}
			else if (Math.Abs(num3 / 2.0 + hyline.GetDPLineDistance(line2) - num4 / 2.0) < 0.0001)
			{
				if ((z < z2 && YJKRevitTools.getDuctHeight(duct1) > YJKRevitTools.getDuctHeight(duct2)) || (z > z2 && YJKRevitTools.getDuctHeight(duct1) < YJKRevitTools.getDuctHeight(duct2)))
				{
					result = 7;
				}
				else if ((z < z2 && YJKRevitTools.getDuctHeight(duct1) < YJKRevitTools.getDuctHeight(duct2)) || (z > z2 && YJKRevitTools.getDuctHeight(duct1) > YJKRevitTools.getDuctHeight(duct2)))
				{
					result = 8;
				}
			}
			return result;
		}

		private static double getDuctHeight(Duct duct)
		{
			double result;
			if (new YJKPiping<Duct>(duct).StartConnector.Connector.Shape == ConnectorSharp.Round)
			{
				result = duct.Diameter;
			}
			else
			{
				result = duct.Height;
			}
			return result;
		}

		public static double getDuctWidth(Duct duct)
		{
			double result;
			if (new YJKPiping<Duct>(duct).StartConnector.Connector.Shape == ConnectorSharp.Round)
			{
				result = duct.Diameter;
			}
			else
			{
				result = duct.Width;
			}
			return result;
		}

		public static Pipe createPipe(double offset, XYZ xyzstart, XYZ xyzend, double diameter, double slope, PipingSystemType pst, PipeType pt, Autodesk.Revit.DB.Document doc)
		{
			double num = xyzstart.DistanceTo(xyzend);
			double num2 = Math.Tan(slope) * num;
			XYZ start = new XYZ(xyzstart.X, xyzstart.Y, xyzstart.Z + offset / 304.8);
			XYZ end = new XYZ(xyzend.X, xyzend.Y, xyzend.Z + offset / 304.8 + num2);
			Pipe result = doc.CreatHYPipe(pst, pt, doc.ActiveView.GenLevel, start, end, diameter);
			doc.Regenerate();
			return result;
		}

		public List<XYZ> getAlignmentPoint(double minLength, double witdh, Line line, double offset)
		{
			List<XYZ> list = new List<XYZ>();
			double num = line.GetEndPoint(0).DistanceTo(line.GetEndPoint(1));
			if (num >= minLength / 304.8)
			{
				int num2 = (int)Math.Ceiling(num / (witdh / 304.8));
				double num3 = num / (double)num2;
				HYCreatePipeHelper hycreatePipeHelper = new HYCreatePipeHelper();
				for (int i = 0; i < num2 - 1; i++)
				{
					XYZ lineXYZList = this.GetLineXYZList(line.GetEndPoint(0), (double)(i + 1) * num3, line);
					XYZ newParallelPipeXYZ = hycreatePipeHelper.getNewParallelPipeXYZ(lineXYZList, line, offset);
					list.Add(newParallelPipeXYZ);
				}
			}
			return list;
		}

		public XYZ GetLineXYZList(XYZ globalPoint, double distance, Line line)
		{
			XYZ result = null;
			XYZ xyz = (line.GetEndPoint(0) - line.GetEndPoint(1)).Normalize() * distance + globalPoint;
			XYZ xyz2 = -(line.GetEndPoint(0) - line.GetEndPoint(1)).Normalize() * distance + globalPoint;
			YJKLine hyline = new YJKLine(line);
			if (hyline.IsPointOnLine(xyz))
			{
				result = xyz;
			}
			else if (hyline.IsPointOnLine(xyz2))
			{
				result = xyz2;
			}
			return result;
		}

		public static XYZ getNewXYZDeriction(XYZ xyz1, XYZ xyz2)
		{
			XYZ result;
			if (Math.Abs(xyz1.X - xyz2.X) < 1E-07)
			{
				if (xyz1.Y > xyz2.Y)
				{
					result = new XYZ((xyz1.X + xyz2.X) / 2.0 + 200.0, (xyz1.Y + xyz2.Y) / 2.0, (xyz1.Z + xyz2.Z) / 2.0);
				}
				else
				{
					result = new XYZ((xyz1.X + xyz2.X) / 2.0 - 200.0, (xyz1.Y + xyz2.Y) / 2.0, (xyz1.Z + xyz2.Z) / 2.0);
				}
			}
			else if (xyz1.X > xyz2.X)
			{
				result = new XYZ((xyz1.X + xyz2.X) / 2.0, (xyz1.Y + xyz2.Y) / 2.0 - 200.0, (xyz1.Z + xyz2.Z) / 2.0);
			}
			else
			{
				result = new XYZ((xyz1.X + xyz2.X) / 2.0, (xyz1.Y + xyz2.Y) / 2.0 + 200.0, (xyz1.Z + xyz2.Z) / 2.0);
			}
			return result;
		}

		public static void FamilyInstanceReplace(Autodesk.Revit.DB.Document doc, FamilyInstance oldFamilyInstance, FamilyInstance newFamilyInstance)
		{
			Element element = null;
			if (oldFamilyInstance.Host != null)
			{
				element = oldFamilyInstance.Host;
			}
			XYZ point = (oldFamilyInstance.Location as LocationPoint).Point;
			if (oldFamilyInstance.Symbol.Family.Category == newFamilyInstance.Symbol.Family.Category)
			{
				try
				{
					oldFamilyInstance.Symbol = newFamilyInstance.Symbol;
					goto IL_EA;
				}
				catch
				{
					doc.DeleteElement(oldFamilyInstance);
					UnifiedModified.ActivateFamilySymbol(newFamilyInstance.Symbol);
					if (newFamilyInstance.Host == null)
					{
						doc.Create.NewFamilyInstance(point, newFamilyInstance.Symbol, (Autodesk.Revit.DB.Structure.StructuralType)0);
					}
					else if (element != null)
					{
						doc.Create.NewFamilyInstance(point, newFamilyInstance.Symbol, element, (Autodesk.Revit.DB.Structure.StructuralType)0);
					}
					goto IL_EA;
				}
			}
			doc.DeleteElement(oldFamilyInstance);
			UnifiedModified.ActivateFamilySymbol(newFamilyInstance.Symbol);
			if (newFamilyInstance.Host == null)
			{
				doc.Create.NewFamilyInstance(point, newFamilyInstance.Symbol, (Autodesk.Revit.DB.Structure.StructuralType)0);
			}
			else if (element != null)
			{
				doc.Create.NewFamilyInstance(point, newFamilyInstance.Symbol, element, (Autodesk.Revit.DB.Structure.StructuralType)0);
			}
			IL_EA:
			doc.Regenerate();
		}

		public static void FamilyInstanceReplaces(Autodesk.Revit.DB.Document doc, FamilyInstance oldFamilyInstance, FamilyInstance newFamilyInstance, bool istrue)
		{
			Element element = null;
			if (oldFamilyInstance.Host != null)
			{
				element = oldFamilyInstance.Host;
			}
			XYZ point = (oldFamilyInstance.Location as LocationPoint).Point;
			XYZ point2 = (newFamilyInstance.Location as LocationPoint).Point;
			if (oldFamilyInstance.Symbol.Family.Name != newFamilyInstance.Symbol.Family.Name && !point.IsAlmostEqualTo(point2))
			{
				doc.DeleteElement(oldFamilyInstance);
				UnifiedModified.ActivateFamilySymbol(newFamilyInstance.Symbol);
				if (newFamilyInstance.Host == null)
				{
					doc.Create.NewFamilyInstance(point, newFamilyInstance.Symbol, (Autodesk.Revit.DB.Structure.StructuralType)0);
				}
				else if (element != null)
				{
					doc.Create.NewFamilyInstance(point, newFamilyInstance.Symbol, element, (Autodesk.Revit.DB.Structure.StructuralType)0);
				}
				doc.Regenerate();
				return;
			}
		}

		public static Pipe getNewPipe(Pipe pipe, XYZ xyz, Autodesk.Revit.DB.Document doc)
		{
			LocationCurve locationCurve = pipe.Location as LocationCurve;
			Line curve = (pipe.Location as LocationCurve).Curve as Line;
			XYZ hyendPoint = curve.GetEndPoint(0);
			XYZ hyendPoint2 = curve.GetEndPoint(1);
			if (hyendPoint.DistanceTo(xyz) < hyendPoint2.DistanceTo(xyz))
			{
				Line curve2 = doc.CreatYJKLine(hyendPoint2, xyz, true);
				locationCurve.Curve = curve2;
			}
			else if (hyendPoint.DistanceTo(xyz) > hyendPoint2.DistanceTo(xyz))
			{
				Line curve3 = doc.CreatYJKLine(hyendPoint, xyz, true);
				locationCurve.Curve = curve3;
			}
			return pipe;
		}

		public static FamilyInstance LayFamilySymbol(Autodesk.Revit.DB.Document doc, XYZ xyz, FamilySymbol familySymbol, double angle)
		{
			UnifiedModified.ActivateFamilySymbol(familySymbol);
			FamilyInstance familyInstance = doc.Create.NewFamilyInstance(xyz, familySymbol, (Autodesk.Revit.DB.Structure.StructuralType)0);
			doc.Regenerate();
			new YJKRotateFamilyInstance().RotateElem(doc, familyInstance, angle);
			return familyInstance;
		}

		public static FamilyInstance LayFamilySymbol(Autodesk.Revit.DB.Document doc, XYZ xyz, FamilySymbol familySymbol, Level level, double angle)
		{
			UnifiedModified.ActivateFamilySymbol(familySymbol);
			FamilyInstance familyInstance = doc.Create.NewFamilyInstance(xyz, familySymbol, level, (Autodesk.Revit.DB.Structure.StructuralType)0);
			doc.Regenerate();
			new YJKRotateFamilyInstance().RotateElem(doc, familyInstance, angle);
			return familyInstance;
		}

		public static bool isRiserPiping(Element pipe1)
		{
			bool result = false;
			if (pipe1.Location is LocationCurve)
			{
				XYZ hyendPoint = (pipe1.Location as LocationCurve).Curve.GetEndPoint(0);
				XYZ hyendPoint2 = (pipe1.Location as LocationCurve).Curve.GetEndPoint(1);
				if (Math.Abs(hyendPoint.X - hyendPoint2.X) < 0.001 && Math.Abs(hyendPoint.Y - hyendPoint2.Y) < 0.001 && Math.Abs(hyendPoint.Z - hyendPoint2.Z) > 0.015)
				{
					result = true;
				}
			}
			return result;
		}

		public static bool isRiserPipe(Pipe pipe1)
		{
			bool result = false;
			XYZ hyendPoint = (pipe1.Location as LocationCurve).Curve.GetEndPoint(0);
			XYZ hyendPoint2 = (pipe1.Location as LocationCurve).Curve.GetEndPoint(1);
			if (Math.Abs(hyendPoint.X - hyendPoint2.X) < 0.0001 && Math.Abs(hyendPoint.Y - hyendPoint2.Y) < 0.0001 && Math.Abs(hyendPoint.Z - hyendPoint2.Z) > 0.015)
			{
				result = true;
			}
			return result;
		}

		public static bool isRiserCableTray(CableTray cableTray)
		{
			bool result = false;
			XYZ hyendPoint = (cableTray.Location as LocationCurve).Curve.GetEndPoint(0);
			XYZ hyendPoint2 = (cableTray.Location as LocationCurve).Curve.GetEndPoint(1);
			if (Math.Abs(hyendPoint.X - hyendPoint2.X) < 0.0001 && Math.Abs(hyendPoint.Y - hyendPoint2.Y) < 0.0001 && Math.Abs(hyendPoint.Z - hyendPoint2.Z) > 0.015)
			{
				result = true;
			}
			return result;
		}

		public static bool isRiserConduit(Conduit conduit)
		{
			bool result = false;
			XYZ hyendPoint = (conduit.Location as LocationCurve).Curve.GetEndPoint(0);
			XYZ hyendPoint2 = (conduit.Location as LocationCurve).Curve.GetEndPoint(1);
			if (Math.Abs(hyendPoint.X - hyendPoint2.X) < 0.0001 && Math.Abs(hyendPoint.Y - hyendPoint2.Y) < 0.0001 && Math.Abs(hyendPoint.Z - hyendPoint2.Z) > 0.015)
			{
				result = true;
			}
			return result;
		}

		public static bool IsRiserDuct(Duct duct)
		{
			bool result = false;
			XYZ hyendPoint = (duct.Location as LocationCurve).Curve.GetEndPoint(0);
			XYZ hyendPoint2 = (duct.Location as LocationCurve).Curve.GetEndPoint(1);
			if (Math.Abs(hyendPoint.X - hyendPoint2.X) < 0.0001 && Math.Abs(hyendPoint.Y - hyendPoint2.Y) < 0.0001 && Math.Abs(hyendPoint.Z - hyendPoint2.Z) > 0.015)
			{
				result = true;
			}
			return result;
		}

		public List<Pipe> TwoPipesOneisRightAndOneIsNot(Pipe pipe1, Pipe pipe2)
		{
			List<Pipe> list = new List<Pipe>();
			if (YJKRevitTools.isRiserPipe(pipe1) && !YJKRevitTools.isRiserPipe(pipe2))
			{
				list.Add(pipe1);
				list.Add(pipe2);
			}
			else if (YJKRevitTools.isRiserPipe(pipe2) && !YJKRevitTools.isRiserPipe(pipe1))
			{
				list.Add(pipe2);
				list.Add(pipe1);
			}
			return list;
		}

		public static bool PipeAlignment(Pipe pipe1, Pipe pipe2, double distanceRange)
		{
			bool result;
			try
			{
				Document document = pipe1.Document;
				if (YJKRevitTools.isRiserPipe(pipe1) && YJKRevitTools.isRiserPipe(pipe2))
				{
					result = false;
				}
				else
				{
					bool flag;
					if (!YJKRevitTools.isRiserPipe(pipe1) && !YJKRevitTools.isRiserPipe(pipe2))
					{
						flag = YJKRevitTools.HorizontalPipeAlignment(pipe1, pipe2, document);
					}
					else
					{
						flag = YJKRevitTools.RiserPipeAlignment(pipe1, pipe2, distanceRange);
					}
					result = flag;
				}
			}
			catch (Exception)
			{
				result = false;
			}
			return result;
		}

		private static bool RiserPipeAlignment(Pipe pipe1, Pipe pipe2, double distanceRange)
		{
			LocationCurve locationCurve = pipe1.Location as LocationCurve;
			LocationCurve locationCurve2 = pipe2.Location as LocationCurve;
			Line curve = locationCurve.Curve as Line;
			Line curve2 = locationCurve2.Curve as Line;
			XYZ hyendPoint = curve.GetEndPoint(0);
			XYZ hyendPoint2 = curve.GetEndPoint(1);
			XYZ hyendPoint3 = curve2.GetEndPoint(0);
			XYZ hyendPoint4 = curve2.GetEndPoint(1);
			bool result = false;
			if (YJKRevitTools.isRiserPipe(pipe1))
			{
				XYZ dlineP = YJKRevitTools.GetDLineP(hyendPoint, hyendPoint2, hyendPoint3, hyendPoint4);
				double num = dlineP.DistanceTo(new XYZ(hyendPoint.X, hyendPoint.Y, dlineP.Z));
				if (distanceRange > num || distanceRange == 0.0)
				{
					Location location = pipe2.Location as LocationCurve;
					XYZ xyz = new XYZ(hyendPoint.X, hyendPoint.Y, dlineP.Z) - dlineP;
					location.Move(num * xyz.Normalize());
					result = true;
				}
			}
			else
			{
				XYZ dlineP2 = YJKRevitTools.GetDLineP(hyendPoint3, hyendPoint4, hyendPoint, hyendPoint2);
				double num2 = dlineP2.DistanceTo(new XYZ(hyendPoint3.X, hyendPoint3.Y, dlineP2.Z));
				if (distanceRange > num2 || distanceRange == 0.0)
				{
					Location location2 = pipe2.Location as LocationCurve;
					XYZ xyz2 = dlineP2 - new XYZ(hyendPoint3.X, hyendPoint3.Y, dlineP2.Z);
					location2.Move(num2 * xyz2.Normalize());
					result = true;
				}
			}
			return result;
		}

		private static bool HorizontalPipeAlignment(Pipe pipe1, Pipe pipe2, Autodesk.Revit.DB.Document doc)
		{
			bool result = false;
			try
			{
				YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(pipe1);
				YJKPiping<Pipe> hypiping2 = new YJKPiping<Pipe>(pipe2);
				double num = pipe1.get_Parameter(BuiltInParameter.RBS_PIPE_SLOPE).AsDouble();
				double num2 = pipe2.get_Parameter(BuiltInParameter.RBS_PIPE_SLOPE).AsDouble();
				if (Math.Abs(num - num2) > 0.05)
				{
					return false;
				}
				double xydistance = hypiping.GetXYDistance(hypiping2.Piping);
				XYZ xyvector = hypiping.GetXYVector(hypiping2.Piping);
				LocationCurve locationCurve = hypiping2.Piping.Location as LocationCurve;
				if (locationCurve != null)
				{
					locationCurve.Move(xydistance * xyvector);
					XYZ origin = hypiping.GetCloseConnector(hypiping2.StartConnector.Origin, false).Origin;
					XYZ origin2 = hypiping.GetDistanceConnector(hypiping2.StartConnector.Origin).Origin;
					XYZ origin3 = hypiping2.GetCloseConnector(hypiping.StartConnector.Origin, false).Origin;
					XYZ origin4 = hypiping2.GetDistanceConnector(hypiping.StartConnector.Origin).Origin;
					double num3 = (origin.Z - origin2.Z) * origin2.DistanceTo(origin3) / origin.DistanceTo(origin2) + origin2.Z;
					double num4 = (origin.Z - origin2.Z) * origin2.DistanceTo(origin4) / origin.DistanceTo(origin2) + origin2.Z;
					XYZ xyz = new XYZ(origin3.X, origin3.Y, num3);
					XYZ xyz2 = new XYZ(origin4.X, origin4.Y, num4);
					Line curve = Line.CreateBound(xyz, xyz2);
					locationCurve.Curve = curve;
				}
				ElementTransformUtils.MoveElement(doc, pipe2.Id, new XYZ(1E-05, 1E-05, 1E-05));
				ElementTransformUtils.MoveElement(doc, pipe2.Id, -1.0 * new XYZ(1E-05, 1E-05, 1E-05));
				result = true;
			}
			catch (Exception)
			{
				return false;
			}
			return result;
		}

		public static double DistanceTwoXYZ(XYZ xyz1, XYZ xyz2)
		{
			return xyz1.DistanceTo(xyz2);
		}

		public static XYZ GetVectorByHorizontal(XYZ hVector)
		{
			new XYZ();
			return new XYZ(0.0, 0.0, 1.0).CrossProduct(hVector);
		}

		public static XYZ GetXYZByDistance(XYZ startXYZ, XYZ endXYZ, double distance)
		{
			XYZ xyz = (endXYZ - startXYZ).Normalize();
			return endXYZ + distance * xyz;
		}

		public static void DrawDetailLine(Autodesk.Revit.DB.Document doc, Autodesk.Revit.DB.View view, XYZ sPoint, XYZ ePoint)
		{
			Curve curve = doc.CreatYJKLine(sPoint, ePoint, true);
			doc.Create.NewDetailCurve(view, curve);
		}

		public static DetailCurve DrawRangLine(Autodesk.Revit.DB.Document doc, XYZ originPoint, double radius)
		{
			Autodesk.Revit.DB.View activeView = doc.ActiveView;
			double startAngle = 0.0;
			double endAngle = Math.PI*2;
			Curve curve = doc.CreatYJKArc(originPoint, radius, startAngle, endAngle, XYZ.BasisX, XYZ.BasisY);
			return doc.Create.NewDetailCurve(activeView, curve);
		}

		public static ModelLine DrawModelLine(Autodesk.Revit.DB.Document doc, Curve curve, SketchPlane sketchPlane)
		{
			return doc.Create.NewModelCurve(curve, sketchPlane) as ModelLine;
		}

		public static ModelLine DrawModelLine(Autodesk.Revit.DB.Document doc, XYZ ptStart, XYZ ptEnd, SketchPlane sketchPlane)
		{
			Curve curve = YJKLineEx.YJKGetBound(ptStart, ptEnd);
			return YJKRevitTools.DrawModelLine(doc, curve, sketchPlane);
		}

		public static Connector GetConnectConnector(Connector connector)
		{
			Connector result = null;
			if (connector.IsConnected)
			{
				ConnectorSetIterator connectorSetIterator = connector.AllRefs.ForwardIterator();
				while (connectorSetIterator.MoveNext())
				{
					object obj = connectorSetIterator.Current;
					Connector connector2 = obj as Connector;
					if (connector2 != null && connector2.Owner.UniqueId != connector.Owner.UniqueId && ((int)connector2.ConnectorType == 1 || (int)connector2.ConnectorType == 2 || (int)connector2.ConnectorType == 19))
					{
						result = connector2;
						break;
					}
				}
			}
			return result;
		}

		public static IList<XYZ> GetElementEndPoint(Element elem)
		{
			List<XYZ> list = new List<XYZ>();
			LocationCurve locationCurve = elem.Location as LocationCurve;
			XYZ hyendPoint = locationCurve.Curve.GetEndPoint(0);
			XYZ hyendPoint2 = locationCurve.Curve.GetEndPoint(1);
			((IList<XYZ>)list).Insert(0, new XYZ(hyendPoint.X, hyendPoint.Y, 0.0));
			((IList<XYZ>)list).Insert(1, new XYZ(hyendPoint2.X, hyendPoint2.Y, 0.0));
			return list;
		}

		public static IList<XYZ> OrderPipePoint(Pipe pipe, XYZ intersectionPnt)
		{
			List<XYZ> list = new List<XYZ>();
			XYZ xyz = YJKRevitTools.GetElementCurve(pipe, 0);
			XYZ xyz2 = YJKRevitTools.GetElementCurve(pipe, 1);
			if (intersectionPnt.DistanceTo(xyz) < intersectionPnt.DistanceTo(xyz2))
			{
				XYZ xyz3 = xyz;
				xyz = xyz2;
				xyz2 = xyz3;
			}
			((IList<XYZ>)list).Insert(0, xyz);
			((IList<XYZ>)list).Insert(1, xyz2);
			return list;
		}

		public static void ChangePipeSlop(ref Pipe pipe, XYZ startPnt, XYZ endPnt)
		{
			LocationCurve locationCurve = pipe.Location as LocationCurve;
			Line curve = pipe.Document.CreatYJKLine(startPnt, endPnt, true);
			locationCurve.Curve = curve;
		}

		public static void ChangeDuctLine(ref Duct duct, XYZ point)
		{
			Document document = duct.Document;
			LocationCurve locationCurve = duct.Location as LocationCurve;
			XYZ hyendPoint = locationCurve.Curve.GetEndPoint(0);
			XYZ hyendPoint2 = locationCurve.Curve.GetEndPoint(1);
			XYZ point2 = (point.DistanceTo(hyendPoint) > point.DistanceTo(hyendPoint2)) ? hyendPoint : hyendPoint2;
			Line curve = document.CreatYJKLine(point2, point, true);
			locationCurve.Curve = curve;
			document.Regenerate();
		}

		public static void ChangePipeSlop(ref Pipe pipe, Line line)
		{
			(pipe.Location as LocationCurve).Curve = line;
		}

		public static Line GetPipeLine(Autodesk.Revit.DB.Document doc, XYZ startPnt, XYZ endPnt, XYZ intersectionPnt)
		{
			XYZ xyz = new XYZ(startPnt.X, startPnt.Y, 0.0);
			XYZ xyz2 = new XYZ(endPnt.X, endPnt.Y, 0.0);
			double num = xyz.DistanceTo(xyz2);
			double num2 = intersectionPnt.DistanceTo(xyz);
			double num3 = (intersectionPnt.Z - startPnt.Z) * num / num2;
			endPnt = new XYZ(endPnt.X, endPnt.Y, startPnt.Z + num3);
			return doc.CreatYJKLine(startPnt, endPnt, true);
		}

		public static double GetSlopValue(XYZ startPnt, XYZ endPnt, XYZ intersectionPnt)
		{
			XYZ xyz = new XYZ(startPnt.X, startPnt.Y, 0.0);
			XYZ xyz2 = new XYZ(endPnt.X, endPnt.Y, 0.0);
			double num = xyz.DistanceTo(xyz2);
			double num2 = intersectionPnt.DistanceTo(xyz);
			return (endPnt.Z - startPnt.Z) * num2 / num;
		}

		public static double GetEndValue(XYZ startPnt, XYZ endPnt, XYZ pnt)
		{
			XYZ xyz = new XYZ(startPnt.X, startPnt.Y, 0.0);
			XYZ xyz2 = new XYZ(endPnt.X, endPnt.Y, 0.0);
			XYZ xyz3 = new XYZ(pnt.X, pnt.Y, 0.0);
			double num = xyz.DistanceTo(xyz2);
			double num2 = xyz3.DistanceTo(xyz);
			return (pnt.Z - startPnt.Z) * num / num2;
		}

		public static IList<XYZ> GetSlopPoint(Pipe pipe, XYZ pnt)
		{
			IList<XYZ> list = new List<XYZ>();
			if (pipe == null || pnt == null)
			{
				return null;
			}
			XYZ xyz = YJKRevitTools.GetElementCurve(pipe, 0);
			XYZ xyz2 = YJKRevitTools.GetElementCurve(pipe, 1);
			if (xyz.Z > xyz2.Z)
			{
				XYZ xyz3 = xyz;
				xyz = xyz2;
				xyz2 = xyz3;
			}
			double endValue = YJKRevitTools.GetEndValue(xyz, xyz2, pnt);
			list.Add(xyz);
			xyz2 = new XYZ(xyz2.X, xyz2.Y, xyz.Z + endValue);
			list.Add(xyz2);
			return list;
		}

		public static XYZ GetElementCurve(Element elem, int index)
		{
			return (elem.Location as LocationCurve).Curve.GetEndPoint(index);
		}

		public static DetailLine DrawDetailLine(Autodesk.Revit.DB.Document doc, XYZ sPoint, XYZ ePoint)
		{
			Curve curve = doc.CreatYJKLine(sPoint, ePoint, true);
			DetailLine detailLine = doc.Create.NewDetailCurve(doc.ActiveView, curve) as DetailLine;
			ElementSet elementSet = new ElementSet();
			elementSet.Insert(detailLine);
			if (detailLine.IsHidden(doc.ActiveView))
			{
				doc.ActiveView.UnHideYJKElements(elementSet);
			}
			return detailLine;
		}

		public static Dictionary<XYZ, XYZ> GetDLEndPoint(XYZ minPoint, XYZ maxPoint, double xDis, double yDis)
		{
			Dictionary<XYZ, XYZ> dictionary = new Dictionary<XYZ, XYZ>();
			double num = minPoint.X;
			double num2 = maxPoint.Y;
			if (xDis <= 0.0 && yDis <= 0.0)
			{
				return dictionary;
			}
			if (xDis > 0.0)
			{
				do
				{
					XYZ key = new XYZ(num, minPoint.Y, 0.0);
					XYZ value = new XYZ(num, maxPoint.Y, 0.0);
					dictionary.Add(key, value);
					num += xDis;
				}
				while (num < maxPoint.X);
			}
			if (yDis > 0.0)
			{
				do
				{
					XYZ key2 = new XYZ(minPoint.X, num2, 0.0);
					XYZ value2 = new XYZ(maxPoint.X, num2, 0.0);
					dictionary.Add(key2, value2);
					num2 -= yDis;
				}
				while (num2 > minPoint.Y);
			}
			return dictionary;
		}

		public static Dictionary<XYZ, XYZ> GetDLEndPoint(XYZ xOnePoint, XYZ xTwoPoint, XYZ yPoint, double xDis, double yDis)
		{
			Dictionary<XYZ, XYZ> dictionary = new Dictionary<XYZ, XYZ>();
			double num = xOnePoint.DistanceTo(xTwoPoint);
			double num2 = yPoint.DistanceTo(xTwoPoint);
			XYZ xyz = (xTwoPoint - xOnePoint).Normalize();
			XYZ xyz2 = (yPoint - xTwoPoint).Normalize();
			XYZ key = new XYZ(0.0, 0.0, 0.0);
			XYZ value = new XYZ(0.0, 0.0, 0.0);
			double num3 = 0.0;
			double num4 = 0.0;
			if (xDis > 0.0)
			{
				do
				{
					key = xOnePoint + num3 * xyz;
					value = xOnePoint + num3 * xyz + num2 * xyz2;
					dictionary.Add(key, value);
					num3 += xDis;
				}
				while (num3 < num);
			}
			if (yDis > 0.0)
			{
				do
				{
					key = xOnePoint + num4 * xyz2;
					value = xTwoPoint + num4 * xyz2;
					dictionary.Add(key, value);
					num4 += yDis;
				}
				while (num4 < num2);
			}
			return dictionary;
		}

		public static IList<XYZ> GetDiagonalPoint(XYZ onePoint, XYZ twoPoint, double xSide, double ySide)
		{
			List<XYZ> list = new List<XYZ>();
			double num = (onePoint.X > twoPoint.X) ? twoPoint.X : onePoint.X;
			double num2 = (onePoint.X < twoPoint.X) ? twoPoint.X : onePoint.X;
			double num3 = (onePoint.Y > twoPoint.Y) ? twoPoint.Y : onePoint.Y;
			double num4 = (onePoint.Y < twoPoint.Y) ? twoPoint.Y : onePoint.Y;
			XYZ item = new XYZ(num + xSide, num3, 0.0);
			XYZ item2 = new XYZ(num2, num4 - ySide, 0.0);
			((IList<XYZ>)list).Insert(0, item);
			((IList<XYZ>)list).Insert(1, item2);
			return list;
		}

		public static IList<XYZ> GetDiagonalPoint(XYZ onePoint, XYZ twoPoint, XYZ yPoint, double xSide, double ySide)
		{
			IList<XYZ> list = new List<XYZ>();
			XYZ xyz = (twoPoint - onePoint).Normalize();
			YJKLine hyline = new YJKLine(onePoint, twoPoint);
			hyline.MakeUnBound();
			XYZ project = hyline.GetProject(yPoint);
			XYZ xyz2 = (yPoint - project).Normalize();
			hyline = new YJKLine(twoPoint, twoPoint + xyz2);
			hyline.MakeUnBound();
			XYZ item = onePoint + ySide * xyz2 + xSide * xyz;
			XYZ item2 = twoPoint + ySide * xyz2;
			list.Insert(0, item);
			list.Insert(1, item2);
			if (hyline.IsPointOnLine(yPoint))
			{
				list.Insert(2, yPoint);
			}
			else
			{
				list.Insert(2, hyline.GetProject(yPoint));
			}
			return list;
		}

		public static void SetDetailLineView(ICollection<ElementId> ids, ExternalCommandData commandData)
		{
			System.Drawing.Color color = new Autodesk.Revit.DB.Color(200, 200, 200);
			commandData.Application.ActiveUIDocument.Document.ActiveView.SetYJKProjColorOverrideByElement(ids, color);
		}

		public static void SetSystemSimple(Autodesk.Revit.DB.Document doc, Duct duct)
		{
			string ductSystemTypeCH = YJKRevitTools.GetDuctSystemTypeCH((duct.MEPSystem as MechanicalSystem).SystemType.ToString());
			string text;
			if (!(ductSystemTypeCH == "送风"))
			{
				if (!(ductSystemTypeCH == "回风"))
				{
					if (!(ductSystemTypeCH == "排风"))
					{
						text = "FG";
					}
					else
					{
						text = "PFG";
					}
				}
				else
				{
					text = "HFG";
				}
			}
			else
			{
				text = "SFG";
			}
			Parameter parameter = doc.GetElementById(duct.MEPSystem.GetTypeId()).get_Parameter(BuiltInParameter.RBS_SYSTEM_ABBREVIATION_PARAM);
			if (parameter.AsString() == "")
			{
				parameter.Set(text);
			}
		}

		public static string JudgePointLineSite(XYZ judgePoint, XYZ lPointOne, XYZ lPointTwo)
		{
			string result = "左";
			double num = (lPointTwo.Y - lPointOne.Y) * judgePoint.X + (lPointOne.X - lPointTwo.X) * judgePoint.Y + (lPointTwo.X * lPointOne.Y - lPointOne.X * lPointTwo.Y);
			if (num > 0.0)
			{
				result = "右";
			}
			else if (num == 0.0)
			{
				result = "中";
			}
			else if (num < 0.0)
			{
				result = "左";
			}
			return result;
		}

		public static double GetDuctWidthorDiameter(Duct duct)
		{
			double result = 0.0;
			foreach (object obj in duct.ConnectorManager.Connectors)
			{
				Connector connector = (Connector)obj;
				if (connector.Shape != ConnectorSharp.Oval)
				{
					if (connector.Shape == ConnectorSharp.Rect)
					{
						result = duct.get_Parameter(BuiltInParameter.RBS_CURVE_WIDTH_PARAM).AsDouble();
					}
					else if (connector.Shape == ConnectorSharp.Round)
					{
						result = duct.get_Parameter(BuiltInParameter.RBS_CURVE_DIAMETER_PARAM).AsDouble();
					}
				}
			}
			return result;
		}

		public static double GetDuctHeightorDiameter(Duct duct)
		{
			double result = 0.0;
			foreach (object obj in duct.ConnectorManager.Connectors)
			{
				Connector connector = (Connector)obj;
				if (connector.Shape != ConnectorSharp.Oval)
				{
					if (connector.Shape == ConnectorSharp.Rect)
					{
						result = duct.get_Parameter(BuiltInParameter.RBS_CURVE_HEIGHT_PARAM).AsDouble();
					}
					else if (connector.Shape == ConnectorSharp.Round)
					{
						result = duct.get_Parameter(BuiltInParameter.RBS_CURVE_DIAMETER_PARAM).AsDouble();
					}
				}
			}
			return result;
		}

		public static bool ModifyDuctWidthHeight(Duct duct, int width, int height)
		{
			bool result;
			try
			{
				bool flag = false;
				foreach (object obj in duct.ConnectorManager.Connectors)
				{
					Connector connector = (Connector)obj;
					if (connector.Shape == ConnectorSharp.Oval || connector.Shape == ConnectorSharp.Rect)
					{
						flag = duct.get_Parameter(BuiltInParameter.RBS_CURVE_WIDTH_PARAM).Set((double)width / 304.8);
						if (!flag)
						{
							return false;
						}
						flag = duct.get_Parameter(BuiltInParameter.RBS_CURVE_HEIGHT_PARAM).Set((double)height / 304.8);
					}
					else if (connector.Shape == ConnectorSharp.Round)
					{
						flag = duct.get_Parameter(BuiltInParameter.RBS_CURVE_DIAMETER_PARAM).Set((double)width / 304.8);
					}
				}
				result = flag;
			}
			catch (Exception)
			{
				throw;
			}
			return result;
		}

		public static bool ShareParaBeExist(Element element, string pName)
		{
			bool result = false;
			foreach (object obj in element.Parameters)
			{
				Parameter parameter = (Parameter)obj;
				if (parameter.IsShared && parameter.Definition.Name == pName)
				{
					result = true;
					break;
				}
			}
			return result;
		}

		public static void ModifyDuctWidthHeight(Autodesk.Revit.DB.Document doc, ElementId elemId, int width, int height)
		{
			foreach (Element element in YJKElementFilter.GetElementByClass(typeof(Duct), doc))
			{
				if (element.Id == elemId)
				{
					YJKRevitTools.ModifyDuctWidthHeight(element as Duct, width, height);
				}
			}
		}

		public static void SetSystemSimple(Autodesk.Revit.DB.Document doc, Pipe pipe)
		{
			if (pipe.MEPSystem != null)
			{
				string pipeSystemTypeCH = YJKRevitTools.GetPipeSystemTypeCH((pipe.MEPSystem as PipingSystem).SystemType.ToString());
				uint num = YArchitech.Revit.PrivateImplementationDetails.ComputeStringHash(pipeSystemTypeCH);
				string text;
				if (num <= 2563745786u)
				{
					if (num <= 1366947159u)
					{
						if (num != 1229342730u)
						{
							if (num == 1366947159u)
							{
								if (pipeSystemTypeCH == "通风孔")
								{
									text = "TFK";
									goto IL_184;
								}
							}
						}
						else if (pipeSystemTypeCH == "家用热水")
						{
							text = "JYRS";
							goto IL_184;
						}
					}
					else if (num != 2187079225u)
					{
						if (num == 2563745786u)
						{
							if (pipeSystemTypeCH == "干式消防系统")
							{
								text = "GSXF";
								goto IL_184;
							}
						}
					}
					else if (pipeSystemTypeCH == "循环供水")
					{
						text = "XHGS";
						goto IL_184;
					}
				}
				else if (num <= 3914730892u)
				{
					if (num != 2731895364u)
					{
						if (num == 3914730892u)
						{
							if (pipeSystemTypeCH == "卫生设备")
							{
								text = "WSSB";
								goto IL_184;
							}
						}
					}
					else if (pipeSystemTypeCH == "循环回水")
					{
						text = "XHHS";
						goto IL_184;
					}
				}
				else if (num != 4079822120u)
				{
					if (num == 4199473803u)
					{
						if (pipeSystemTypeCH == "湿式消防系统")
						{
							text = "SSXF";
							goto IL_184;
						}
					}
				}
				else if (pipeSystemTypeCH == "家用冷水")
				{
					text = "JYLS";
					goto IL_184;
				}
				text = "SG";
				IL_184:
				Parameter parameter = doc.GetElementById(pipe.MEPSystem.GetTypeId()).get_Parameter(BuiltInParameter.RBS_SYSTEM_ABBREVIATION_PARAM);
				if (parameter.AsString() == "")
				{
					parameter.Set(text);
					return;
				}
			}
			else
			{
				MessageBox.Show("该立管没有系统分类。请先让它与其他存在系统分类的管道连接后再标记。或在绘制立管前请先手动画一条管道再用绘制立管功能。");
			}
		}

		public static void DeleteTagOfElement(Autodesk.Revit.DB.Document doc, BuiltInCategory builtInCategory, Element elem)
		{
			foreach (Element element in YJKRevitTools.GetAllTag(doc, builtInCategory))
			{
				IndependentTag independentTag = element as IndependentTag;
				if (independentTag != null && independentTag.TaggedLocalElementId.IntegerValue == elem.Id.IntegerValue)
				{
					doc.DeleteElement(independentTag);
				}
			}
		}

		public static void DeleteTagOfElement(Autodesk.Revit.DB.Document doc, BuiltInCategory builtInCategory, Element elem, string szName, bool bName)
		{
			foreach (Element element in YJKRevitTools.GetAllTag(doc, builtInCategory))
			{
				IndependentTag independentTag = element as IndependentTag;
				if (independentTag != null)
				{
					if (bName)
					{
						if (independentTag.TaggedLocalElementId.IntegerValue == elem.Id.IntegerValue && independentTag.Name == szName)
						{
							doc.DeleteElement(independentTag);
						}
					}
					else if (independentTag.TaggedLocalElementId.IntegerValue == elem.Id.IntegerValue && independentTag.Name != szName)
					{
						doc.DeleteElement(independentTag);
					}
				}
			}
		}

		public static ICollection<Element> GetAllTag(Autodesk.Revit.DB.Document doc, BuiltInCategory builtInCategory)
		{
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc);
			ElementOwnerViewFilter elementOwnerViewFilter = new ElementOwnerViewFilter(doc.ActiveView.Id);
			return filteredElementCollector.WherePasses(elementOwnerViewFilter).OfCategory(builtInCategory).OfClass(typeof(IndependentTag)).ToList<Element>();
		}

		public static Duct NewDuct(Duct sourceDuct, XYZ startXYZ, XYZ endXYZ)
		{
			Duct duct = null;
			if (sourceDuct == null || startXYZ == null || endXYZ == null)
			{
				return null;
			}
			Document document = sourceDuct.Document;
			YJKDocument hydocument = new YJKDocument(document);
			foreach (ElementId elementId in ElementTransformUtils.CopyElement(document, sourceDuct.Id, new XYZ(0.0, 0.0, 0.0)))
			{
				duct = (hydocument.GetElement(elementId) as Duct);
			}
			document.Regenerate();
			if (duct != null)
			{
				Line curve = YJKLineEx.YJKGetBound(startXYZ, endXYZ);
				(duct.Location as LocationCurve).Curve = curve;
			}
			document.Regenerate();
			return duct;
		}

		public static FlexDuct NewFlexDuct(FlexDuct sourceFlexDuct, XYZ startXYZ, XYZ endXYZ)
		{
			FlexDuct flexDuct = null;
			if (sourceFlexDuct == null || startXYZ == null || endXYZ == null)
			{
				return null;
			}
			Document document = sourceFlexDuct.Document;
			YJKDocument hydocument = new YJKDocument(document);
			foreach (ElementId elementId in ElementTransformUtils.CopyElement(document, sourceFlexDuct.Id, new XYZ(0.0, 0.0, 0.0)))
			{
				flexDuct = (hydocument.GetElement(elementId) as FlexDuct);
			}
			document.Regenerate();
			if (flexDuct != null)
			{
				Line curve = YJKLineEx.YJKGetBound(startXYZ, endXYZ);
				(flexDuct.Location as LocationCurve).Curve = curve;
			}
			document.Regenerate();
			return flexDuct;
		}

		public static FlexDuct NewFlexDuct(XYZ startXYZ, XYZ endXYZ, FlexDuctType flexDuctType, Autodesk.Revit.DB.Document doc)
		{
			if (startXYZ == null || endXYZ == null)
			{
				return null;
			}
			IList<XYZ> list = new List<XYZ>();
			list.Add(startXYZ);
			list.Add(endXYZ);
			FlexDuct result = doc.Create.NewFlexDuct(list, flexDuctType);
			doc.Regenerate();
			return result;
		}

		public static Space CreatSpace(Autodesk.Revit.DB.Document doc, Room room)
		{
			Space result = null;
			LocationPoint locationPoint = room.Location as LocationPoint;
			Level level = room.GetLevel();
			if (level != null && locationPoint != null && room.UpperLimit != null)
			{
				Space space = doc.Create.NewSpace(level, new UV(locationPoint.Point.X, locationPoint.Point.Y));
				space.Name = room.Name.Split(new char[]
				{
					' '
				})[0];
				space.UpperLimit = room.UpperLimit;
				space.LimitOffset = room.LimitOffset;
				space.BaseOffset = room.BaseOffset;
				Parameter parameter = space.GetParameter("基础房间ID");
				if (parameter != null)
				{
					parameter.Set(room.Id.ToString());
				}
				result = space;
			}
			return result;
		}

		public static Space CreatSpace(Autodesk.Revit.DB.Document doc, Room room, Transform tsForm, ref IList<Level> listLevel)
		{
			Space result = null;
			LocationPoint locationPoint = room.Location as LocationPoint;
			UV uv = new UV();
			XYZ xyz = locationPoint.Point + tsForm.Origin;
			uv = new UV(xyz.X, xyz.Y);
			Level level = room.GetLevel();
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc);
			filteredElementCollector.OfClass(typeof(Level)).OfCategory(BuiltInCategory.OST_Levels);
			bool flag = false;
			foreach (Element element in filteredElementCollector)
			{
				Level level2 = element as Level;
				if (Math.Abs(level2.Elevation - level.Elevation) < 0.001)
				{
					flag = true;
					level = level2;
					break;
				}
			}
			bool flag2 = false;
			if (!flag)
			{
				IEnumerator<Level> enumerator2 = listLevel.GetEnumerator();
				{
					while (enumerator2.MoveNext())
					{
						if (enumerator2.Current.Name == level.Name)
						{
							flag2 = true;
						}
					}
				}
				if (!flag2)
				{
					listLevel.Add(level);
					YJKMessageBox.Show("链接模型中" + level.Name + "标高没有对应的标高\n将不会根据房间创建该标高的空间");
				}
				return null;
			}
			if (level != null && locationPoint != null)
			{
				Space space = doc.Create.NewSpace(level, uv);
				space.Name = room.Name.Split(new char[]
				{
					' '
				})[0];
				Parameter parameter = space.GetParameter("基础房间ID");
				if (parameter != null)
				{
					parameter.Set(room.Id.ToString());
				}
				result = space;
			}
			return result;
		}

		public static FamilySymbol GetFamilySymbol(string familyName, Autodesk.Revit.DB.Document doc)
		{
			List<Element> elementByClass = YJKElementFilter.GetElementByClass(typeof(FamilySymbol), doc);
			FamilySymbol result = null;
			if (elementByClass.Count <= 0)
			{
				return null;
			}
			foreach (Element element in elementByClass)
			{
				FamilySymbol familySymbol = element as FamilySymbol;
				if (familySymbol != null && familySymbol.Family.Name == familyName)
				{
					result = familySymbol;
					break;
				}
			}
			return result;
		}

		public static FamilySymbol GetFamilySymbol(string familyName, string fsName, Autodesk.Revit.DB.Document doc, BuiltInCategory builtInCategory)
		{
			List<Element> elementByCategory = YJKElementFilter.GetElementByCategory(doc, typeof(FamilySymbol), builtInCategory);
			FamilySymbol result = null;
			if (elementByCategory.Count <= 0)
			{
				return null;
			}
			foreach (Element element in elementByCategory)
			{
				FamilySymbol familySymbol = element as FamilySymbol;
				if (familySymbol != null && familySymbol.Family.Name + ".rfa" == familyName && familySymbol.Name == fsName)
				{
					result = familySymbol;
					break;
				}
			}
			return result;
		}

		public static bool isExsitSpace(Room room, IList<Space> listSpace)
		{
			bool result = false;
			foreach (Space space in listSpace)
			{
				if (space.Room != null && space.Room.Id == room.Id)
				{
					result = true;
					break;
				}
				if (space.GetBoundarySegments(new SpatialElementBoundaryOptions()).Count > 0 && space.GetParameter("基础房间ID").AsString() == room.Id.ToString())
				{
					result = true;
					break;
				}
			}
			return result;
		}

		public static Pipe NewPipe(Pipe sourcePipe, XYZ startXYZ, XYZ endXYZ)
		{
			Pipe pipe = null;
			if (sourcePipe == null || startXYZ == null || endXYZ == null)
			{
				return null;
			}
			Document document = sourcePipe.Document;
			YJKDocument hydocument = new YJKDocument(document);
			foreach (ElementId elementId in ElementTransformUtils.CopyElement(document, sourcePipe.Id, new XYZ(0.0, 0.0, 0.0)))
			{
				pipe = (hydocument.GetElement(elementId) as Pipe);
			}
			document.Regenerate();
			if (pipe != null)
			{
				Line curve = YJKLineEx.YJKGetBound(startXYZ, endXYZ);
				(pipe.Location as LocationCurve).Curve = curve;
			}
			document.Regenerate();
			ElementTransformUtils.MoveElement(pipe.Document, pipe.Id, new XYZ(0.001, 0.001, 0.001));
			ElementTransformUtils.MoveElement(pipe.Document, pipe.Id, -1.0 * new XYZ(0.001, 0.001, 0.001));
			return pipe;
		}

		public static MEPCurve NewMepCurve(MEPCurve sourcePipe, XYZ startXYZ, XYZ endXYZ)
		{
			MEPCurve mepcurve = null;
			if (sourcePipe == null || startXYZ == null || endXYZ == null)
			{
				return null;
			}
			Document document = sourcePipe.Document;
			YJKDocument hydocument = new YJKDocument(document);
			foreach (ElementId elementId in ElementTransformUtils.CopyElement(document, sourcePipe.Id, new XYZ(0.0, 0.0, 0.0)))
			{
				mepcurve = (hydocument.GetElement(elementId) as MEPCurve);
			}
			document.Regenerate();
			if (mepcurve != null)
			{
				Line curve = YJKLineEx.YJKGetBound(startXYZ, endXYZ);
				(mepcurve.Location as LocationCurve).Curve = curve;
			}
			document.Regenerate();
			ElementTransformUtils.MoveElement(mepcurve.Document, mepcurve.Id, new XYZ(0.001, 0.001, 0.001));
			ElementTransformUtils.MoveElement(mepcurve.Document, mepcurve.Id, -1.0 * new XYZ(0.001, 0.001, 0.001));
			return mepcurve;
		}

		public static Pipe NewPipe(Pipe sourcePipe, Connector startConnetor, XYZ endXYZ)
		{
			if (sourcePipe == null || startConnetor == null || endXYZ == null)
			{
				return null;
			}
			Pipe pipe = YJKRevitTools.NewPipe(sourcePipe, startConnetor.Origin, endXYZ);
			pipe.get_Parameter(BuiltInParameter.RBS_PIPE_DIAMETER_PARAM).Set(startConnetor.Radius * 2.0);
			return pipe;
		}

		public static Pipe NewPipe(Pipe sourcePipe, Connector startConnetor, Connector endConnetor)
		{
			if (sourcePipe == null || startConnetor == null || endConnetor == null)
			{
				return null;
			}
			Pipe result;
			if (startConnetor.Radius != endConnetor.Radius)
			{
				result = YJKRevitTools.NewPipe(sourcePipe, startConnetor.Origin, endConnetor.Origin);
			}
			else
			{
				result = YJKRevitTools.NewPipe(sourcePipe, startConnetor, endConnetor.Origin);
			}
			return result;
		}

		public static List<Connector> GetConnectorEnd(Duct duct)
		{
			List<Connector> list = new List<Connector>();
			ConnectorSetIterator connectorSetIterator = duct.ConnectorManager.Connectors.ForwardIterator();
			while (connectorSetIterator.MoveNext())
			{
				object obj = connectorSetIterator.Current;
				Connector connector = obj as Connector;
				if (connector != null && 1 == (int)connector.ConnectorType)
				{
					list.Add(connector);
				}
			}
			return list;
		}

		public static List<Connector> GetConnectorCurve(Duct duct)
		{
			List<Connector> list = new List<Connector>();
			ConnectorSetIterator connectorSetIterator = duct.ConnectorManager.Connectors.ForwardIterator();
			while (connectorSetIterator.MoveNext())
			{
				object obj = connectorSetIterator.Current;
				Connector connector = obj as Connector;
				if (connector != null && 2 == (int)connector.ConnectorType)
				{
					list.Add(connector);
				}
			}
			return list;
		}

		public static List<Connector> GetConnectorAll(Duct duct)
		{
			List<Connector> list = new List<Connector>();
			ConnectorSetIterator connectorSetIterator = duct.ConnectorManager.Connectors.ForwardIterator();
			while (connectorSetIterator.MoveNext())
			{
				object obj = connectorSetIterator.Current;
				Connector connector = obj as Connector;
				if (connector != null && (2 == (int)connector.ConnectorType || 1 == (int)connector.ConnectorType))
				{
					list.Add(connector);
				}
			}
			return list;
		}

		public static List<Connector> GetConnectorAll(MEPCurve mepCurve)
		{
			List<Connector> list = new List<Connector>();
			ConnectorSetIterator connectorSetIterator = mepCurve.ConnectorManager.Connectors.ForwardIterator();
			while (connectorSetIterator.MoveNext())
			{
				object obj = connectorSetIterator.Current;
				Connector connector = obj as Connector;
				if (connector != null && (2 == (int)connector.ConnectorType || 1 == (int)connector.ConnectorType))
				{
					list.Add(connector);
				}
			}
			return list;
		}

		public static List<Connector> GetCurveEndConnectors(MEPCurve mepCurve)
		{
			List<Connector> list = new List<Connector>();
			ConnectorSetIterator connectorSetIterator = mepCurve.ConnectorManager.Connectors.ForwardIterator();
			while (connectorSetIterator.MoveNext())
			{
				object obj = connectorSetIterator.Current;
				Connector connector = obj as Connector;
				if (connector != null && 1 == (int)connector.ConnectorType)
				{
					list.Add(connector);
				}
			}
			return list;
		}

		public static List<Connector> GetConnectorAll(Pipe pipe)
		{
			List<Connector> list = new List<Connector>();
			ConnectorSetIterator connectorSetIterator = pipe.ConnectorManager.Connectors.ForwardIterator();
			while (connectorSetIterator.MoveNext())
			{
				object obj = connectorSetIterator.Current;
				Connector connector = obj as Connector;
				if (connector != null && (2 == (int)connector.ConnectorType || 1 == (int)connector.ConnectorType))
				{
					list.Add(connector);
				}
			}
			return list;
		}

		public static List<Connector> GetConnectorAll(FlexDuct flexDuct)
		{
			List<Connector> list = new List<Connector>();
			ConnectorSetIterator connectorSetIterator = flexDuct.ConnectorManager.Connectors.ForwardIterator();
			while (connectorSetIterator.MoveNext())
			{
				object obj = connectorSetIterator.Current;
				Connector connector = obj as Connector;
				if (connector != null && (2 == (int)connector.ConnectorType || 1 == (int)connector.ConnectorType))
				{
					list.Add(connector);
				}
			}
			return list;
		}

		public static XYZ GetDLineP(XYZ pA, XYZ pB, XYZ pC, XYZ pD)
		{
			double x = pA.X;
			double y = pA.Y;
			double z = pA.Z;
			double x2 = pB.X;
			double y2 = pB.Y;
			double z2 = pB.Z;
			double x3 = pC.X;
			double y3 = pC.Y;
			double z3 = pC.Z;
			double x4 = pD.X;
			double y4 = pD.Y;
			double z4 = pD.Z;
			double num = x2 - x;
			double num2 = y2 - y;
			double num3 = z2 - z;
			double num4 = x4 - x3;
			double num5 = y4 - y3;
			double num6 = z4 - z3;
			double num7 = num * num2 * num5 - num2 * num2 * num4 - num3 * num3 * num4 + num * num3 * num6;
			double num8 = num * num * num5 - num * num2 * num4 - num2 * num3 * num6 + num3 * num3 * num5;
			double num9 = num * num3 * num4 - num * num * num6 - num2 * num2 * num6 + num2 * num3 * num5;
			double num10 = -x * num7 + y * num8 - z * num9;
			double num11;
			if (Math.Abs(num7 * num4 - num8 * num5 + num9 * num6) < 1E-06)
			{
				num11 = 0.0;
			}
			else
			{
				num11 = (num8 * y3 - num7 * x3 - num9 * z3 - num10) / (num7 * num4 - num8 * num5 + num9 * num6);
			}
			double num12 = num4 * num11 + x3;
			double num13 = num5 * num11 + y3;
			double num14 = num6 * num11 + z3;
			return new XYZ(num12, num13, num14);
		}

		public static bool IsLineSegmentCross(XYZ firPnt, XYZ secPnt, XYZ sPipePnt, XYZ ePipePnt)
		{
			double num = firPnt.X * (sPipePnt.Y - secPnt.Y) + secPnt.X * (firPnt.Y - sPipePnt.Y) + sPipePnt.X * (secPnt.Y - firPnt.Y);
			double num2 = firPnt.X * (ePipePnt.Y - secPnt.Y) + secPnt.X * (firPnt.Y - ePipePnt.Y) + ePipePnt.X * (secPnt.Y - firPnt.Y);
			if (num * num2 >= 0.0 && (num != 0.0 || num2 != 0.0))
			{
				return false;
			}
			num = sPipePnt.X * (firPnt.Y - ePipePnt.Y) + ePipePnt.X * (sPipePnt.Y - firPnt.Y) + firPnt.X * (ePipePnt.Y - sPipePnt.Y);
			num2 = sPipePnt.X * (secPnt.Y - ePipePnt.Y) + ePipePnt.X * (sPipePnt.Y - secPnt.Y) + secPnt.X * (ePipePnt.Y - sPipePnt.Y);
			return num * num2 < 0.0 || (num == 0.0 && num2 == 0.0);
		}

		public static string GetDuctSystemTypeCH(string enumName)
		{
			uint num = YArchitech.Revit.PrivateImplementationDetails.ComputeStringHash(enumName);
			if (num <= 2603360416u)
			{
				if (num != 81264407u)
				{
					if (num != 1678934222u)
					{
						if (num == 2603360416u)
						{
							if (enumName == "Fitting")
							{
								return "管件";
							}
						}
					}
					else if (enumName == "Global")
					{
						return "全局";
					}
				}
				else if (enumName == "ExhaustAir")
				{
					return "排风";
				}
			}
			else if (num <= 3891676362u)
			{
				if (num != 3017983553u)
				{
					if (num == 3891676362u)
					{
						if (enumName == "UndefinedSystemType")
						{
							return "未定义";
						}
					}
				}
				else if (enumName == "ReturnAir")
				{
					return "回风";
				}
			}
			else if (num != 3995932714u)
			{
				if (num == 4199155463u)
				{
					if (enumName == "OtherAir")
					{
						return "其他通风";
					}
				}
			}
			else if (enumName == "SupplyAir")
			{
				return "送风";
			}
			return "未定义";
		}

		public static string GetPipeSystemTypeCH(string enumName)
		{
			uint num = YArchitech.Revit.PrivateImplementationDetails.ComputeStringHash(enumName);
			if (num <= 2003677185u)
			{
				if (num <= 1524890971u)
				{
					if (num != 514019971u)
					{
						if (num != 842668758u)
						{
							if (num == 1524890971u)
							{
								if (enumName == "DomesticHotWater")
								{
									return "家用热水";
								}
							}
						}
						else if (enumName == "SupplyHydronic")
						{
							return "循环供水";
						}
					}
					else if (enumName == "ReturnHydronic")
					{
						return "循环回水";
					}
				}
				else if (num <= 1698412355u)
				{
					if (num != 1678934222u)
					{
						if (num == 1698412355u)
						{
							if (enumName == "FireProtectPreaction")
							{
								return "预作用消防系统";
							}
						}
					}
					else if (enumName == "Global")
					{
						return "全局";
					}
				}
				else if (num != 1807552510u)
				{
					if (num == 2003677185u)
					{
						if (enumName == "FireProtectDry")
						{
							return "干式消防系统";
						}
					}
				}
				else if (enumName == "Sanitary")
				{
					return "卫生设备";
				}
			}
			else if (num <= 2482186404u)
			{
				if (num != 2017692542u)
				{
					if (num != 2382714854u)
					{
						if (num == 2482186404u)
						{
							if (enumName == "FireProtectWet")
							{
								return "湿式消防系统";
							}
						}
					}
					else if (enumName == "DomesticColdWater")
					{
						return "家用冷水";
					}
				}
				else if (enumName == "Vent")
				{
					return "通风孔";
				}
			}
			else if (num <= 3313474090u)
			{
				if (num != 2603360416u)
				{
					if (num == 3313474090u)
					{
						if (enumName == "FireProtectOther")
						{
							return "其他消防系统";
						}
					}
				}
				else if (enumName == "Fitting")
				{
					return "管件";
				}
			}
			else if (num != 3891676362u)
			{
				if (num == 4225100969u)
				{
					if (enumName == "OtherPipe")
					{
						return "其他";
					}
				}
			}
			else if (enumName == "UndefinedSystemType")
			{
				return "未定义";
			}
			return "未定义";
		}

		public static string GetSpaceTypeName(SpaceType spaceType, UIApplication uiApp)
		{
			string result = "";
			LanguageType language = uiApp.Application.Language;
			if (language != null)
			{
				if (language == 6)
				{
					switch (spaceType)
					{
					case -1:
						result = "";
						break;
					case 0:
						result = "活动区";
						break;
					case 1:
						result = "活动区 - 医院/保健中心";
						break;
					case 2:
						result = "飞机/火车/公共汽车 - 行李区";
						break;
					case 3:
						result = "机场 - 中央广场";
						break;
					case 4:
						result = "天井 - 其他每一层";
						break;
					case 5:
						result = "天井 - 前三层";
						break;
					case 6:
						result = "观众席/坐席 - 监狱";
						break;
					case 7:
						result = "观众席/坐席 - 运动中心";
						break;
					case 8:
						result = "观众席/坐席 - 体育馆";
						break;
					case 9:
						result = "观众席/坐席 - 体育场";
						break;
					case 10:
						result = "观众席/坐席 - 会议中心";
						break;
					case 11:
						result = "观众席/坐席 - 电影院";
						break;
					case 12:
						result = "观众席/坐席 - 剧院";
						break;
					case 13:
						result = "观众席/坐席 - 宗教";
						break;
					case 14:
						result = "观众席/坐席 - 警察局/消防队";
						break;
					case 15:
						result = "观众席/坐席 - 法院";
						break;
					case 16:
						result = "观众席/坐席 - 礼堂";
						break;
					case 17:
						result = "银行客户区";
						break;
					case 18:
						result = "银行业务活动区 - 办公室";
						break;
					case 19:
						result = "理发美容店";
						break;
					case 20:
						result = "卡片目录与编目 - 图书馆";
						break;
					case 21:
						result = "教室/演讲室/培训室 - 监狱";
						break;
					case 22:
						result = "教室/演讲室/培训室";
						break;
					case 23:
						result = "禁闭室 - 监狱";
						break;
					case 24:
						result = "禁闭室 - 法院";
						break;
					case 25:
						result = "会议室/多功能厅";
						break;
					case 26:
						result = "走廊/过道";
						break;
					case 27:
						result = "走廊/过道 - 制造厂";
						break;
					case 28:
						result = "候诊患者走廊 - 医院/保健中心";
						break;
					case 29:
						result = "运动场地 - 体育场";
						break;
					case 30:
						result = "法庭 - 法院";
						break;
					case 31:
						result = "百货公司销售区 - 零售店";
						break;
					case 32:
						result = "车间 - 制造厂";
						break;
					case 33:
						result = "餐饮区";
						break;
					case 34:
						result = "餐饮区 - 旅馆";
						break;
					case 35:
						result = "餐饮区 - 餐饮连锁店";
						break;
					case 36:
						result = "餐饮区 - 餐饮娱乐场所";
						break;
					case 37:
						result = "餐饮区 - 汽车旅馆";
						break;
					case 38:
						result = "餐饮区 - 运输部门";
						break;
					case 39:
						result = "餐饮区 - 监狱";
						break;
					case 40:
						result = "餐饮区 - 行政机构";
						break;
					case 41:
						result = "宿舍卧室";
						break;
					case 42:
						result = "宿舍自习室";
						break;
					case 43:
						result = "化妆室/衣帽室/换衣间 - 体育馆";
						break;
					case 44:
						result = "化妆室/衣帽室/换衣间 - 法院";
						break;
					case 45:
						result = "化妆室/衣帽室/换衣间 - 剧院";
						break;
					case 46:
						result = "化妆室/衣帽室/换衣间 - 礼堂";
						break;
					case 47:
						result = "化妆室/衣帽室/换衣间 - 运动中心";
						break;
					case 48:
						result = "电气/机械";
						break;
					case 49:
						result = "电梯间";
						break;
					case 50:
						result = "急救室 - 医院/保健中心";
						break;
					case 51:
						result = "控制室 - 制造厂";
						break;
					case 52:
						result = "检查/治疗室 - 医院/保健中心";
						break;
					case 53:
						result = "运动区 - 运动中心";
						break;
					case 54:
						result = "运动区 - 体育馆";
						break;
					case 55:
						result = "展览区 - 会议中心";
						break;
					case 56:
						result = "教堂 - 宗教建筑";
						break;
					case 57:
						result = "精细材质 - 仓库";
						break;
					case 58:
						result = "精品销售区 - 零售店";
						break;
					case 59:
						result = "消防队消防车库 - 警察局/消防队";
						break;
					case 60:
						result = "食物准备室";
						break;
					case 61:
						result = "修理厂服务/维修间 - 汽车工厂";
						break;
					case 62:
						result = "普通高开间 - 制造厂";
						break;
					case 63:
						result = "普通低开间 - 制造厂";
						break;
					case 64:
						result = "普通展览 - 博物馆";
						break;
					case 65:
						result = "医院 - 婴儿室 - 医院/保健中心";
						break;
					case 66:
						result = "医院/医疗用品处 - 医院/保健中心 ";
						break;
					case 67:
						result = "医院/放射科 - 医院/保健中心";
						break;
					case 68:
						result = "旅馆/会议中心 - 会议";
						break;
					case 69:
						result = "非活动区";
						break;
					case 70:
						result = "审判席 - 法院";
						break;
					case 71:
						result = "L实验室 - 办公室";
						break;
					case 72:
						result = "洗衣店 - 熨烫和整理";
						break;
					case 73:
						result = "洗衣店 - 洗衣 - 医院/保健中心";
						break;
					case 74:
						result = "图书馆 - 视听室 - 图书馆视听室";
						break;
					case 75:
						result = "生活区 - 宿舍";
						break;
					case 76:
						result = "生活区 - 汽车旅馆";
						break;
					case 77:
						result = "生活区 - 旅馆";
						break;
					case 78:
						result = "大厅";
						break;
					case 79:
						result = "大厅 - 宗教建筑";
						break;
					case 80:
						result = "大厅 - 电影院";
						break;
					case 81:
						result = "大厅 - 礼堂";
						break;
					case 82:
						result = "大厅 - 剧院";
						break;
					case 83:
						result = "大厅 - 邮局";
						break;
					case 84:
						result = "大厅 - 旅馆";
						break;
					case 85:
						result = "休闲娱乐场所";
						break;
					case 86:
						result = "购物商场销售区 - 零售店";
						break;
					case 87:
						result = "大众促销区 - 零售店";
						break;
					case 88:
						result = "中型/大型材质 - 仓库";
						break;
					case 89:
						result = "促销区 - 零售店";
						break;
					case 90:
						result = "博物馆及画廊 - 仓库 - 博物馆及画廊 - 仓库";
						break;
					case 91:
						result = "护士室 - 医院/保健中心";
						break;
					case 92:
						result = "办公室 - 封闭";
						break;
					case 93:
						result = "办公室 - 开放";
						break;
					case 94:
						result = "办公室公共活动区 - 非活动区";
						break;
					case 95:
						result = "手术室 - 医院/保健中心";
						break;
					case 96:
						result = "其他电视播放区 - 体育场";
						break;
					case 97:
						result = "停车区 - 仅出席人员 - 停车库";
						break;
					case 98:
						result = "停车区 - 行人 - 停车库";
						break;
					case 99:
						result = "病房 - 医院/保健中心";
						break;
					case 100:
						result = "个人服务销售区 - 零售店";
						break;
					case 101:
						result = "药房 - 医院/保健中心";
						break;
					case 102:
						result = "理疗室 - 医院/保健中心";
						break;
					case 103:
						result = "活动区 - 体育馆";
						break;
					case 104:
						result = "正压送风系统";
						break;
					case 105:
						result = "警察局实验室 - 警察局/消防队";
						break;
					case 106:
						result = "公共休息室和员工休息室 - 医院/保健中心";
						break;
					case 107:
						result = "阅览区 - 图书馆";
						break;
					case 108:
						result = "接待处/等待区 - 运输部门";
						break;
					case 109:
						result = "接待处/等待区 - 汽车旅馆";
						break;
					case 110:
						result = "接待处/等待区 - 旅馆";
						break;
					case 111:
						result = "康复室 - 医院/保健中心";
						break;
					case 112:
						result = "修复室 - 博物馆";
						break;
					case 113:
						result = "公共卫生间";
						break;
					case 114:
						result = "环形体育场 - 体育场";
						break;
					case 115:
						result = "休息室 - 警察局/消防队";
						break;
					case 116:
						result = "分拣区 - 邮局";
						break;
					case 117:
						result = "特产商店销售区 - 零售店 ";
						break;
					case 118:
						result = "书库 - 图书馆";
						break;
					case 119:
						result = "楼梯 - 非活动区";
						break;
					case 120:
						result = "楼梯";
						break;
					case 121:
						result = "超市销售区 - 零售店";
						break;
					case 122:
						result = "车站 - 售票处 - 运输部门";
						break;
					case 123:
						result = "车间 - 车间";
						break;
					case 124:
						result = "礼拜 - 牧师唱诗班席位 - 宗教";
						break;
					case 125:
						result = "";
						break;
					}
				}
			}
			else
			{
				switch (spaceType)
				{
				case -1:
					result = "";
					break;
				case 0:
					result = "Active Storage";
					break;
				case 1:
					result = "Active Storage - Hospital/Healthcare";
					break;
				case 2:
					result = "Air/Train/Bus - Baggage Area";
					break;
				case 3:
					result = "Airport - Concourse";
					break;
				case 4:
					result = "Atrium - Each Additional Floor";
					break;
				case 5:
					result = "Atrium - First Three Floors";
					break;
				case 6:
					result = "Audience/Seating Area - Penitentiary";
					break;
				case 7:
					result = "Audience/Seating Area - Exercise Center";
					break;
				case 8:
					result = "Audience/Seating Area - Gymnasium";
					break;
				case 9:
					result = "Audience/Seating Area - Sports Arena";
					break;
				case 10:
					result = "Audience/Seating Area - Convention Center";
					break;
				case 11:
					result = "Audience/Seating Area - Motion Picture Theatre";
					break;
				case 12:
					result = "Audience/Seating Area - Performing Arts Theatre";
					break;
				case 13:
					result = "Audience/Seating Area - Religious";
					break;
				case 14:
					result = "Audience/Seating Area - Police/Fire Stations";
					break;
				case 15:
					result = "Audience/Seating Area - Court House";
					break;
				case 16:
					result = "Audience/Seating Area - Auditorium";
					break;
				case 17:
					result = "Bank Customer Area";
					break;
				case 18:
					result = "Banking Activity Area - Office";
					break;
				case 19:
					result = "Barber and Beauty Parlor";
					break;
				case 20:
					result = "Card File and Cataloguing - Library";
					break;
				case 21:
					result = "Classroom/Lecture/Training - Penitentiary";
					break;
				case 22:
					result = "Classroom/Lecture/Training";
					break;
				case 23:
					result = "Confinement Cells - Penitentiary";
					break;
				case 24:
					result = "Confinement Cells - Courthouse";
					break;
				case 25:
					result = "Conference Meeting/Multipurpose";
					break;
				case 26:
					result = "Corridor/Transition";
					break;
				case 27:
					result = "Corridor/Transition - Manufacturing Facility";
					break;
				case 28:
					result = "Corridors with Patient Waiting Exam - Hospital/Healthcare";
					break;
				case 29:
					result = "Court Sports Area - Sports Arena";
					break;
				case 30:
					result = "Courtroom - Courthouse";
					break;
				case 31:
					result = "Department Store Sales Area - Retail";
					break;
				case 32:
					result = "Detailed - Manufacturing Facility";
					break;
				case 33:
					result = "Dining Area";
					break;
				case 34:
					result = "Dining Area - Hotel";
					break;
				case 35:
					result = "Dining Area - Family Dining";
					break;
				case 36:
					result = "Dining Area - Lounge/Leisure Dining";
					break;
				case 37:
					result = "Dining Area - Motel";
					break;
				case 38:
					result = "Dining Area - Transportation";
					break;
				case 39:
					result = "Dining Area - Penitentiary";
					break;
				case 40:
					result = "Dining Area - Civil Services";
					break;
				case 41:
					result = "Dormitory Bedroom";
					break;
				case 42:
					result = "Dormitory Study Hall";
					break;
				case 43:
					result = "Dressing/Locker/Fitting Room - Gymnasium";
					break;
				case 44:
					result = "Dressing/Locker/Fitting Room - Courthouse";
					break;
				case 45:
					result = "Dressing/Locker/Fitting Room - Performing Arts Theatre";
					break;
				case 46:
					result = "Dressing/Locker/Fitting Room - Auditorium";
					break;
				case 47:
					result = "Dressing/Locker/Fitting Room - Exercise Center";
					break;
				case 48:
					result = "Electrical/Mechanical";
					break;
				case 49:
					result = "Elevator Lobbies";
					break;
				case 50:
					result = "Emergency - Hospital/Healthcare";
					break;
				case 51:
					result = "Equipment Room - Manufacturing Facility";
					break;
				case 52:
					result = "Exam/Treatment - Hospital/Healthcare";
					break;
				case 53:
					result = "Exercise Area - Exercise Center";
					break;
				case 54:
					result = "Exercise Area - Gymnasium";
					break;
				case 55:
					result = "Exhibit Space - Convention Center";
					break;
				case 56:
					result = "Fellowship Hall - Religious Buildings";
					break;
				case 57:
					result = "Fine Material - Warehouse";
					break;
				case 58:
					result = "Fine Merchandise Sales Area - Retail";
					break;
				case 59:
					result = "Fire Station Engine Room - Police/Fire Station";
					break;
				case 60:
					result = "Food Preparation";
					break;
				case 61:
					result = "Garage Service/Repair - Automotive Facility";
					break;
				case 62:
					result = "General High Bay - Manufacturing Facility";
					break;
				case 63:
					result = "General Low Bay - Manufacturing Facility";
					break;
				case 64:
					result = "General Exhibition - Museum";
					break;
				case 65:
					result = "Hospital - Nursery - Hospital/Healthcare";
					break;
				case 66:
					result = "Hospital/Medical Supplies - Hospital/Healthcare";
					break;
				case 67:
					result = "Hospital/Radiology - Hospital/Healthcare";
					break;
				case 68:
					result = "Hotel/Conference Center - Conference/Meeting";
					break;
				case 69:
					result = "Inactive Storage";
					break;
				case 70:
					result = "Judges Chambers - Courthouse";
					break;
				case 71:
					result = "Laboratory - Office";
					break;
				case 72:
					result = "Laundry - Ironing and Sorting";
					break;
				case 73:
					result = "Laundry - Washing - Hospital/Healthcare";
					break;
				case 74:
					result = "Library - Audio Visual - Library-Audio Visual";
					break;
				case 75:
					result = "Living Quarters - Dormitory";
					break;
				case 76:
					result = "Living Quarters - Motel";
					break;
				case 77:
					result = "Living Quarters - Hotel";
					break;
				case 78:
					result = "Lobby";
					break;
				case 79:
					result = "Lobby - Religious Buildings";
					break;
				case 80:
					result = "Lobby - Motion Picture Theatre";
					break;
				case 81:
					result = "Lobby - Auditorium";
					break;
				case 82:
					result = "Lobby - Performing Arts Theatre";
					break;
				case 83:
					result = "Lobby - Post Office";
					break;
				case 84:
					result = "Lobby - Hotel";
					break;
				case 85:
					result = "Lounge/Recreation";
					break;
				case 86:
					result = "Mall Concourse Sales Area - Retail";
					break;
				case 87:
					result = "Mass Merchandising Sales Area - Retail";
					break;
				case 88:
					result = "Medium/Bulky Material - Warehouse";
					break;
				case 89:
					result = "Merchandising Sales Area - Retail";
					break;
				case 90:
					result = "Museum and Gallery - Storage - Museum and Gallery - Storage";
					break;
				case 91:
					result = "Nurse Station - Hospital/Healthcare";
					break;
				case 92:
					result = "Office - Enclosed";
					break;
				case 93:
					result = "Office - Open Plan";
					break;
				case 94:
					result = "Office Common Activity Areas - Inactive Storage";
					break;
				case 95:
					result = "Operating Room - Hospital/Healthcare";
					break;
				case 96:
					result = "Other Televised Playing Area - Sports Arena";
					break;
				case 97:
					result = "Parking Area - Attendant only - Parking Garage";
					break;
				case 98:
					result = "Parking Area - Pedestrian - Parking Garage";
					break;
				case 99:
					result = "Patient Room - Hospital/Healthcare";
					break;
				case 100:
					result = "Personal Services Sales Area - Retail";
					break;
				case 101:
					result = "Pharmacy - Hospital/Healthcare";
					break;
				case 102:
					result = "Physical Therapy - Hospital/Healthcare";
					break;
				case 103:
					result = "Playing Area Gymnasium";
					break;
				case 104:
					result = "Plenum";
					break;
				case 105:
					result = "Police Station Laboratory - Police/Fire Stations";
					break;
				case 106:
					result = "Public and Staff Lounge - Hospital/Healthcare";
					break;
				case 107:
					result = "Reading Area - Library";
					break;
				case 108:
					result = "Reception/Waiting - Transportation";
					break;
				case 109:
					result = "Reception/Waiting - Motel";
					break;
				case 110:
					result = "Reception/Waiting - Hotel";
					break;
				case 111:
					result = "Recovery - Hospital/Healthcare";
					break;
				case 112:
					result = "Restoration - Museum";
					break;
				case 113:
					result = "Restrooms";
					break;
				case 114:
					result = "Ring Sports Area - Sports Arena";
					break;
				case 115:
					result = "Sleeping Quarters - Police/Fire Station";
					break;
				case 116:
					result = "Sorting Area - Post Office";
					break;
				case 117:
					result = "Specialty Store Sales Area - Retail";
					break;
				case 118:
					result = "Stacks - Library";
					break;
				case 119:
					result = "Stairs - Inactive";
					break;
				case 120:
					result = "Stairway";
					break;
				case 121:
					result = "Supermarket Sales Area - Retail";
					break;
				case 122:
					result = "Terminal - Ticket Counter - Transportation";
					break;
				case 123:
					result = "Workshop - Workshop";
					break;
				case 124:
					result = "Worship - Pulpit Choir - Religious";
					break;
				case 125:
					result = "";
					break;
				}
			}
			return result;
		}

		public static Element GetSpaceTypeElment(string steName, Autodesk.Revit.DB.Document doc)
		{
			Element result;
			try
			{
				FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc);
				filteredElementCollector.OfCategory(BuiltInCategory.OST_HVAC_Load_Space_Types);
				Element element = null;
				foreach (Element element2 in filteredElementCollector)
				{
					if (element2.Name == steName)
					{
						element = element2;
						break;
					}
				}
				result = element;
			}
			catch (Exception)
			{
				throw;
			}
			return result;
		}

		public static string GetPipeSystemClassicCH(string enName)
		{
			uint num = YArchitech.Revit.PrivateImplementationDetails.ComputeStringHash(enName);
			if (num <= 1283247613u)
			{
				if (num <= 359720770u)
				{
					if (num != 92451209u)
					{
						if (num != 276313692u)
						{
							if (num == 359720770u)
							{
								if (enName == "Fire Protect Wet")
								{
									return "湿式消防系统";
								}
							}
						}
						else if (enName == "Fire Protect Pre-Action")
						{
							return "预作用消防系统";
						}
					}
					else if (enName == "Return Hydronic")
					{
						return "循环回水";
					}
				}
				else if (num <= 646388368u)
				{
					if (num != 362761762u)
					{
						if (num == 646388368u)
						{
							if (enName == "Undefined SystemType")
							{
								return "未定义";
							}
						}
					}
					else if (enName == "Domestic Cold Water")
					{
						return "家用冷水";
					}
				}
				else if (num != 1246239018u)
				{
					if (num == 1283247613u)
					{
						if (enName == "Domestic Hot Water")
						{
							return "家用热水";
						}
					}
				}
				else if (enName == "Supply Hydronic")
				{
					return "循环供水";
				}
			}
			else if (num <= 1807552510u)
			{
				if (num != 1523235215u)
				{
					if (num != 1678934222u)
					{
						if (num == 1807552510u)
						{
							if (enName == "Sanitary")
							{
								return "卫生设备";
							}
						}
					}
					else if (enName == "Global")
					{
						return "全局";
					}
				}
				else if (enName == "Fire Protect Dry")
				{
					return "干式消防系统";
				}
			}
			else if (num <= 1844248067u)
			{
				if (num != 1811626372u)
				{
					if (num == 1844248067u)
					{
						if (enName == "Other Pipe")
						{
							return "其他";
						}
					}
				}
				else if (enName == "Fire Protect Other")
				{
					return "其他消防系统";
				}
			}
			else if (num != 2017692542u)
			{
				if (num == 2603360416u)
				{
					if (enName == "Fitting")
					{
						return "管件";
					}
				}
			}
			else if (enName == "Vent")
			{
				return "通风孔";
			}
			return enName;
		}

		public static MEPSystemClassification GetMEPSystemClassificationByName(string name)
		{
			uint num = YArchitech.Revit.PrivateImplementationDetails.ComputeStringHash(name);
			if (num <= 2003677185u)
			{
				if (num <= 1041852919u)
				{
					if (num <= 498440003u)
					{
						if (num <= 394102708u)
						{
							if (num != 81264407u)
							{
								if (num == 394102708u)
								{
									if (name == "DataCircuit")
									{
										return 5;
									}
								}
							}
							else if (name == "ExhaustAir")
							{
								return 3;
							}
						}
						else if (num != 487051712u)
						{
							if (num == 498440003u)
							{
								if (name == "Communication")
								{
									return 14;
								}
							}
						}
						else if (name == "SwitchTopology")
						{
							return 27;
						}
					}
					else if (num <= 842668758u)
					{
						if (num != 514019971u)
						{
							if (num == 842668758u)
							{
								if (name == "SupplyHydronic")
								{
									return 7;
								}
							}
						}
						else if (name == "ReturnHydronic")
						{
							return 8;
						}
					}
					else if (num != 1015958679u)
					{
						if (num == 1041852919u)
						{
							if (name == "Recirculation")
							{
								return 21;
							}
						}
					}
					else if (name == "Telephone")
					{
						return 9;
					}
				}
				else if (num <= 1698412355u)
				{
					if (num <= 1524890971u)
					{
						if (num != 1332168733u)
						{
							if (num == 1524890971u)
							{
								if (name == "DomesticHotWater")
								{
									return 19;
								}
							}
						}
						else if (name == "PowerUnBalanced")
						{
							return 31;
						}
					}
					else if (num != 1678934222u)
					{
						if (num == 1698412355u)
						{
							if (name == "FireProtectPreaction")
							{
								return 25;
							}
						}
					}
					else if (name == "Global")
					{
						return 29;
					}
				}
				else if (num <= 1807552510u)
				{
					if (num != 1705189686u)
					{
						if (num == 1807552510u)
						{
							if (name == "Sanitary")
							{
								return 16;
							}
						}
					}
					else if (name == "Storm")
					{
						return 18;
					}
				}
				else if (num != 1905031246u)
				{
					if (num == 2003677185u)
					{
						if (name == "FireProtectDry")
						{
							return 24;
						}
					}
				}
				else if (name == "NurseCall")
				{
					return 12;
				}
			}
			else if (num <= 2818543061u)
			{
				if (num <= 2365059260u)
				{
					if (num <= 2060040202u)
					{
						if (num != 2017692542u)
						{
							if (num == 2060040202u)
							{
								if (name == "PowerBalanced")
								{
									return 30;
								}
							}
						}
						else if (name == "Vent")
						{
							return 17;
						}
					}
					else if (num != 2189078486u)
					{
						if (num == 2365059260u)
						{
							if (name == "CableTrayConduit")
							{
								return 32;
							}
						}
					}
					else if (name == "FireAlarm")
					{
						return 11;
					}
				}
				else if (num <= 2482186404u)
				{
					if (num != 2382714854u)
					{
						if (num == 2482186404u)
						{
							if (name == "FireProtectWet")
							{
								return 23;
							}
						}
					}
					else if (name == "DomesticColdWater")
					{
						return 20;
					}
				}
				else if (num != 2603360416u)
				{
					if (num == 2818543061u)
					{
						if (name == "CondensateDrain")
						{
							return 15;
						}
					}
				}
				else if (name == "Fitting")
				{
					return 28;
				}
			}
			else if (num <= 3313474090u)
			{
				if (num <= 3271434715u)
				{
					if (num != 3017983553u)
					{
						if (num == 3271434715u)
						{
							if (name == "Security")
							{
								return 10;
							}
						}
					}
					else if (name == "ReturnAir")
					{
						return 2;
					}
				}
				else if (num != 3307450454u)
				{
					if (num == 3313474090u)
					{
						if (name == "FireProtectOther")
						{
							return 26;
						}
					}
				}
				else if (name == "UndefinedSystemClassification")
				{
					return 0;
				}
			}
			else if (num <= 3995932714u)
			{
				if (num != 3933471113u)
				{
					if (num == 3995932714u)
					{
						if (name == "SupplyAir")
						{
							return 1;
						}
					}
				}
				else if (name == "PowerCircuit")
				{
					return 6;
				}
			}
			else if (num != 4143064631u)
			{
				if (num != 4199155463u)
				{
					if (num == 4225100969u)
					{
						if (name == "OtherPipe")
						{
							return 22;
						}
					}
				}
				else if (name == "OtherAir")
				{
					return 4;
				}
			}
			else if (name == "Controls")
			{
				return 13;
			}
			return 0;
		}

		public static double GetPointToFamilyInstance(FamilyInstance fi, XYZ point)
		{
			return (fi.Location as LocationPoint).Point.DistanceTo(point);
		}

		public static Connector GetElementConnector(Element elem)
		{
			Connector result = null;
			if (elem is FamilyInstance)
			{
				ConnectorSetIterator connectorSetIterator = (elem as FamilyInstance).MEPModel.ConnectorManager.Connectors.ForwardIterator();
				while (connectorSetIterator.MoveNext())
				{
					object obj = connectorSetIterator.Current;
					Connector connector = obj as Connector;
					if (connector != null)
					{
						result = connector;
						break;
					}
				}
			}
			return result;
		}

		public static Connector GetElementOutConnector(Element elem, Domain domain)
		{
			Connector result = null;
			if (elem is FamilyInstance)
			{
				ConnectorManager connectorManager = (elem as FamilyInstance).MEPModel.ConnectorManager;
				if (connectorManager == null)
				{
					return null;
				}
				ConnectorSetIterator connectorSetIterator = connectorManager.Connectors.ForwardIterator();
				while (connectorSetIterator.MoveNext())
				{
					object obj = connectorSetIterator.Current;
					Connector connector = obj as Connector;
					if (connector != null && domain == connector.Domain && connector.Direction == 2)
					{
						result = connector;
						break;
					}
				}
			}
			return result;
		}

		public static Connector GetElementConnector(Domain domain, Element elem)
		{
			Connector result = null;
			if (elem is FamilyInstance)
			{
				ConnectorManager connectorManager = (elem as FamilyInstance).MEPModel.ConnectorManager;
				if (connectorManager == null)
				{
					return null;
				}
				ConnectorSetIterator connectorSetIterator = connectorManager.Connectors.ForwardIterator();
				while (connectorSetIterator.MoveNext())
				{
					object obj = connectorSetIterator.Current;
					Connector connector = obj as Connector;
					if (connector != null && domain == connector.Domain)
					{
						result = connector;
						break;
					}
				}
			}
			return result;
		}

		public static bool SetAnnotationProportation(FamilyInstance fInstance, bool beUse)
		{
			if (fInstance == null)
			{
				return false;
			}
			Parameter parameter = fInstance.GetParameter(BuiltInParameter.RBS_FAMILY_CONTENT_ANNOTATION_DISPLAY);
			if (parameter == null || parameter.IsReadOnly)
			{
				return false;
			}
			int num = 0;
			if (beUse)
			{
				num = 1;
			}
			return parameter.Set(num);
		}

		public static Connector GetElementInConnector(Element elem, Domain domain)
		{
			Connector result = null;
			if (elem is FamilyInstance)
			{
				ConnectorSetIterator connectorSetIterator = (elem as FamilyInstance).MEPModel.ConnectorManager.Connectors.ForwardIterator();
				while (connectorSetIterator.MoveNext())
				{
					object obj = connectorSetIterator.Current;
					Connector connector = obj as Connector;
					if (connector != null && domain == connector.Domain && connector.Direction == 1)
					{
						result = connector;
						break;
					}
				}
			}
			return result;
		}

		public static Connector GetElementUnConnector(Element elem)
		{
			Connector result = null;
			if (elem is FamilyInstance)
			{
				ConnectorSetIterator connectorSetIterator = (elem as FamilyInstance).MEPModel.ConnectorManager.Connectors.ForwardIterator();
				while (connectorSetIterator.MoveNext())
				{
					object obj = connectorSetIterator.Current;
					Connector connector = obj as Connector;
					if (connector != null && !connector.IsConnected)
					{
						result = connector;
						break;
					}
				}
			}
			return result;
		}

		public static Connector GetElementRelDownUnConnector(Element elem)
		{
			Connector result = null;
			double num = double.MaxValue;
			if (elem is FamilyInstance)
			{
				ConnectorSetIterator connectorSetIterator = (elem as FamilyInstance).MEPModel.ConnectorManager.Connectors.ForwardIterator();
				while (connectorSetIterator.MoveNext())
				{
					object obj = connectorSetIterator.Current;
					Connector connector = obj as Connector;
					if (connector != null && !connector.IsConnected && num >= connector.Origin.Z)
					{
						num = connector.Origin.Z;
						result = connector;
					}
				}
			}
			return result;
		}

		public static List<Connector> GetElementAllConnector(Element elem)
		{
			List<Connector> list = new List<Connector>();
			if (elem is FamilyInstance)
			{
				ConnectorManager connectorManager = (elem as FamilyInstance).MEPModel.ConnectorManager;
				if (connectorManager == null)
				{
					return list;
				}
				ConnectorSetIterator connectorSetIterator = connectorManager.Connectors.ForwardIterator();
				while (connectorSetIterator.MoveNext())
				{
					object obj = connectorSetIterator.Current;
					Connector connector = obj as Connector;
					if (connector != null)
					{
						list.Add(connector);
					}
				}
			}
			return list;
		}

		public static List<Connector> GetPipeConnConnector(Pipe pipe)
		{
			List<Connector> list = new List<Connector>();
			ConnectorSetIterator connectorSetIterator = pipe.ConnectorManager.Connectors.ForwardIterator();
			while (connectorSetIterator.MoveNext())
			{
				object obj = connectorSetIterator.Current;
				Connector connector = obj as Connector;
				if (connector.IsConnected)
				{
					list.Add(connector);
				}
			}
			return list;
		}

		public static List<Connector> GetElementConnector(FamilyInstance elem, Domain domain)
		{
			List<Connector> list = new List<Connector>();
			if (elem != null)
			{
				ConnectorSetIterator connectorSetIterator = elem.MEPModel.ConnectorManager.Connectors.ForwardIterator();
				while (connectorSetIterator.MoveNext())
				{
					object obj = connectorSetIterator.Current;
					Connector connector = obj as Connector;
					if (connector != null && connector.Domain == domain)
					{
						list.Add(connector);
					}
				}
			}
			return list;
		}

		public bool ConnectPipeToEquipment(FamilyInstance elem, Pipe pipe)
		{
			bool result = false;
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(pipe);
			foreach (Connector connector in YJKRevitTools.GetElementConnector(elem, (Autodesk.Revit.DB.Domain)3))
			{
				if (connector.PipeSystemType == hypiping.StartConnector.Connector.PipeSystemType)
				{
					if (connector.Origin.IsAlmostEqualTo(hypiping.StartConnector.Origin))
					{
						connector.ConnectTo(hypiping.StartConnector.Connector);
					}
					else
					{
						connector.ConnectTo(hypiping.EndConnector.Connector);
					}
					result = true;
					break;
				}
			}
			return result;
		}

		public static void ChangeThickness(Autodesk.Revit.DB.Document doc, WallType wallType, double dWidth)
		{
			Transaction transaction = new Transaction(doc, "修改保温层厚度");
			try
			{
				transaction.Start();
				if (dWidth < 5.0)
				{
					dWidth = 5.0;
				}
				CompoundStructure compoundStructure = wallType.GetCompoundStructure();
				bool flag = false;
				IList<CompoundStructureLayer> layers = compoundStructure.GetLayers();
				foreach (CompoundStructureLayer compoundStructureLayer in layers)
				{
					if ((int)compoundStructureLayer.Function == 3)
					{
						flag = true;
						compoundStructureLayer.Width = dWidth / 304.8;
					}
				}
				if (!flag)
				{
					CompoundStructureLayer compoundStructureLayer2 = new CompoundStructureLayer();
					compoundStructureLayer2.Function = 3;
					FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc);
					filteredElementCollector.OfClass(typeof(Material));
					FilteredElementIterator elementIterator = filteredElementCollector.GetElementIterator();
					elementIterator.Reset();
					while (elementIterator.MoveNext())
					{
						Element element = elementIterator.Current;
						Material material = element as Material;
						if (material.Name.Contains("隔热层"))
						{
							compoundStructureLayer2.MaterialId = material.Id;
							break;
						}
					}
					compoundStructureLayer2.Width = dWidth / 304.8;
					layers.Insert(0, compoundStructureLayer2);
				}
				compoundStructure.SetLayers(layers);
				wallType.SetCompoundStructure(compoundStructure);
				transaction.Commit();
			}
			catch (Exception ex)
			{
				transaction.RollBack();
				throw ex;
			}
		}

		public static Element GetSameNameElement(ICollection<Element> collection, string name)
		{
			Element result = null;
			foreach (Element element in collection)
			{
				if (element != null && element.Name == name)
				{
					result = element;
					break;
				}
			}
			return result;
		}

		public static Element GetContainNameElement(ICollection<Element> collection, string name)
		{
			Element result = null;
			foreach (Element element in collection)
			{
				if (element != null && element.get_Parameter(BuiltInParameter.ALL_MODEL_FAMILY_NAME).AsString().Contains(name))
				{
					result = element;
					break;
				}
			}
			return result;
		}

		public static List<Duct> GetDuctBySection(Autodesk.Revit.DB.Document doc, ConnectorProfileType connectorSharp)
		{
			List<Duct> list = null;
			foreach (Element element in ((IEnumerable<Element>)YJKElementFilter.GetElementByClass(typeof(Duct), doc)))
			{
				if (element != null && element is Duct && new YJKPiping<Duct>(element as Duct).StartConnector.Connector.Shape == connectorSharp)
				{
					list.Add(element as Duct);
				}
			}
			return list;
		}

		public static FamilySymbol GetFamilySymbol(Autodesk.Revit.DB.Document document, string familySymbolName, BuiltInCategory builtInCategory)
		{
			Element sameNameElement = YJKRevitTools.GetSameNameElement(YJKElementFilter.GetElementsOfType(document, typeof(FamilySymbol), builtInCategory).ToList<Element>(), familySymbolName);
			FamilySymbol result = null;
			if (sameNameElement != null)
			{
				result = (sameNameElement as FamilySymbol);
			}
			return result;
		}

		public static bool SetInstanceParameter(UIApplication uiApp, string pathName, string gropeName, List<string> listStr, BuiltInCategory builtInCategory, bool visible, BuiltInParameterGroup paramGroup = -1)
		{
			bool flag = false;
			CategorySet categorySet = uiApp.Application.Create.NewCategorySet();
			Category category = uiApp.ActiveUIDocument.Document.Settings.Categories[builtInCategory];
			categorySet.Insert(category);
			InstanceBinding instanceBinding = uiApp.Application.Create.NewInstanceBinding(categorySet);
			uiApp.Application.SharedParametersFilename = pathName;
			DefinitionFile definitionFile = uiApp.Application.OpenSharedParameterFile();
			DefinitionGroup definitionGroup = definitionFile.Groups.get_Item(gropeName);
			if (definitionGroup == null)
			{
				definitionGroup = definitionFile.Groups.Create(gropeName);
			}
			BindingMap parameterBindings = uiApp.ActiveUIDocument.Document.ParameterBindings;
			foreach (string text in listStr)
			{
				Definition definition = definitionGroup.Definitions.get_Item(text);
				if (definition == null)
				{
					UnifiedModified.GetDefinition(definitionGroup, text, 1, visible, true);
				}
				if (!parameterBindings.Contains(definition))
				{
					if (paramGroup == -1)
					{
						flag = parameterBindings.Insert(definition, instanceBinding);
					}
					else
					{
						flag = parameterBindings.Insert(definition, instanceBinding, paramGroup);
					}
				}
				else if (paramGroup == -1)
				{
					flag = parameterBindings.ReInsert(definition, instanceBinding);
				}
				else
				{
					flag = parameterBindings.ReInsert(definition, instanceBinding, paramGroup);
				}
				if (!flag)
				{
					break;
				}
			}
			return flag;
		}

		public static bool SetInstanceParameter(UIApplication uiApp, string pathName, string gropeName, List<string> listStr, CategorySet categories, bool visible, BuiltInParameterGroup paramGroup = -1)
		{
			bool flag = false;
			InstanceBinding instanceBinding = uiApp.Application.Create.NewInstanceBinding(categories);
			uiApp.Application.SharedParametersFilename = pathName;
			DefinitionFile definitionFile = uiApp.Application.OpenSharedParameterFile();
			DefinitionGroup definitionGroup = definitionFile.Groups.get_Item(gropeName);
			if (definitionGroup == null)
			{
				definitionGroup = definitionFile.Groups.Create(gropeName);
			}
			BindingMap parameterBindings = uiApp.ActiveUIDocument.Document.ParameterBindings;
			foreach (string text in listStr)
			{
				Definition definition = definitionGroup.Definitions.get_Item(text);
				if (definition == null)
				{
					UnifiedModified.GetDefinition(definitionGroup, text, 1, visible, true);
				}
				if (!parameterBindings.Contains(definition))
				{
					if (paramGroup == -1)
					{
						flag = parameterBindings.Insert(definition, instanceBinding);
					}
					else
					{
						flag = parameterBindings.Insert(definition, instanceBinding, paramGroup);
					}
				}
				else if (paramGroup == -1)
				{
					flag = parameterBindings.ReInsert(definition, instanceBinding);
				}
				else
				{
					flag = parameterBindings.ReInsert(definition, instanceBinding, paramGroup);
				}
				if (!flag)
				{
					break;
				}
			}
			return flag;
		}

		public static bool SetInstanceParameter(UIApplication uiApp, string pathName, string gropeName, string paraName, BuiltInCategory builtInCategory, bool visible)
		{
			CategorySet categorySet = uiApp.Application.Create.NewCategorySet();
			Category category = uiApp.ActiveUIDocument.Document.Settings.Categories[builtInCategory];
			categorySet.Insert(category);
			InstanceBinding instanceBinding = uiApp.Application.Create.NewInstanceBinding(categorySet);
			uiApp.Application.SharedParametersFilename = pathName;
			DefinitionFile definitionFile = uiApp.Application.OpenSharedParameterFile();
			DefinitionGroup definitionGroup = definitionFile.Groups.get_Item(gropeName);
			if (definitionGroup == null)
			{
				definitionGroup = definitionFile.Groups.Create(gropeName);
			}
			Definition definition = definitionGroup.Definitions.get_Item(paraName);
			if (definition == null)
			{
				UnifiedModified.GetDefinition(definitionGroup, paraName, 1, visible, true);
			}
			BindingMap parameterBindings = uiApp.ActiveUIDocument.Document.ParameterBindings;
			bool result;
			if (!parameterBindings.Contains(definition))
			{
				result = parameterBindings.Insert(definition, instanceBinding);
			}
			else
			{
				result = parameterBindings.ReInsert(definition, instanceBinding);
			}
			return result;
		}

		public static CategorySet GetBDCategorySet(UIApplication uiApp, BuiltInCategory builtInCategory)
		{
			CategorySet categorySet = uiApp.Application.Create.NewCategorySet();
			Category category = uiApp.ActiveUIDocument.Document.Settings.Categories[builtInCategory];
			categorySet.Insert(category);
			return categorySet;
		}

		public static ElementBinding CreatElemBinding(UIApplication uiApp, CategorySet categorySet, string bindType)
		{
			ElementBinding result = null;
			if (categorySet == null)
			{
				return null;
			}
			if (!(bindType == "type"))
			{
				if (bindType == "instance")
				{
					result = uiApp.Application.Create.NewInstanceBinding(categorySet);
				}
			}
			else
			{
				result = uiApp.Application.Create.NewTypeBinding(categorySet);
			}
			return result;
		}

		public static DefinitionFile OpenShareParamFile(UIApplication uiApp, string shareFilePath)
		{
			if (!File.Exists(shareFilePath) || shareFilePath.Length <= 0)
			{
				return null;
			}
			uiApp.Application.SharedParametersFilename = shareFilePath;
			return uiApp.Application.OpenSharedParameterFile();
		}

		public static bool SetShareParameter(UIApplication uiApp, DefinitionFile defineFile, string groupName, List<string> listParamName, ElementBinding elemBinding, BuiltInParameterGroup bgp)
		{
			bool flag = false;
			DefinitionGroup definitionGroup = defineFile.Groups.get_Item(groupName);
			if (definitionGroup == null)
			{
				definitionGroup = defineFile.Groups.Create(groupName);
			}
			foreach (string text in listParamName)
			{
				Definition definition = definitionGroup.Definitions.get_Item(text);
				if (definition == null)
				{
					UnifiedModified.GetDefinition(definitionGroup, text, 1, true, true);
				}
				flag = uiApp.ActiveUIDocument.Document.ParameterBindings.Insert(definition, elemBinding, bgp);
				if (!flag)
				{
					break;
				}
			}
			return flag;
		}

		public static bool IsEqualBoundary(Space space, Room room)
		{
			bool result = false;
			if (space == null || room == null)
			{
				return result;
			}
			Curve curve = null;
			Curve curve2 = null;
			IEnumerable<IList<BoundarySegment>> boundarySegments = space.GetBoundarySegments(new SpatialElementBoundaryOptions());
			IList<IList<BoundarySegment>> boundarySegments2 = room.GetBoundarySegments(new SpatialElementBoundaryOptions());
			foreach (IList<BoundarySegment> list in boundarySegments)
			{
				foreach (BoundarySegment segment in list)
				{
					curve = UnifiedModified.GetBoundarySegmentCurve(segment);
				}
			}
			foreach (IList<BoundarySegment> list2 in boundarySegments2)
			{
				foreach (BoundarySegment segment2 in list2)
				{
					curve2 = UnifiedModified.GetBoundarySegmentCurve(segment2);
				}
			}
			result = false;
			if (curve.GetEndPoint(0).IsAlmostEqualTo(curve2.GetEndPoint(0)))
			{
				if (curve.GetEndPoint(1).IsAlmostEqualTo(curve2.GetEndPoint(1)))
				{
					result = true;
				}
			}
			else if (curve.GetEndPoint(0).IsAlmostEqualTo(curve2.GetEndPoint(1)) && curve.GetEndPoint(1).IsAlmostEqualTo(curve2.GetEndPoint(0)))
			{
				result = true;
			}
			return result;
		}

		public static void DeleteDLGroups(Autodesk.Revit.DB.Document doc, Element elem, string paraName, bool isPipe)
		{
			Parameter parameter = elem.GetParameter(paraName);
			List<Element> elementByCategory = YJKElementFilter.GetElementByCategory(doc, BuiltInCategory.OST_IOSDetailGroups);
			if (parameter != null && parameter.HasValue)
			{
				List<string> list = parameter.AsString().Split(new char[]
				{
					'*'
				}).ToList<string>();
				foreach (Element element in elementByCategory)
				{
					if (list.Contains(element.Id.ToString()))
					{
						doc.DeleteElement(element);
					}
				}
			}
		}

		public static void DeleteDLGroups(Autodesk.Revit.DB.Document doc, Element elem, string paraName, string groupPara)
		{
			Parameter parameter = elem.GetParameter(paraName);
			List<Element> elementByCategory = YJKElementFilter.GetElementByCategory(doc, BuiltInCategory.OST_IOSDetailGroups);
			if (parameter != null && parameter.HasValue)
			{
				List<string> list = parameter.AsString().Split(new char[]
				{
					'*'
				}).ToList<string>();
				foreach (Element element in elementByCategory)
				{
					if (list.Contains(element.Id.ToString()) && element.GetParameter(groupPara).AsString().Split(new char[]
					{
						'*'
					}).ToList<string>().Contains(elem.Id.ToString()))
					{
						doc.DeleteElement(element);
					}
				}
			}
		}

		public static void DeleteDLGroups(Autodesk.Revit.DB.Document doc, Element elem, string paraName)
		{
			Parameter parameter = elem.GetParameter(paraName);
			foreach (Element element in YJKElementFilter.GetElementByCategory(doc, BuiltInCategory.OST_IOSDetailGroups))
			{
				string text = parameter.AsString();
				if (text != null && text.Contains(element.Id.ToString()))
				{
					doc.DeleteElement(element);
				}
			}
		}

		public static List<string> GetLinkFilePaths(Autodesk.Revit.DB.Document doc)
		{
			YJKDocument hydocument = new YJKDocument(doc);
			List<string> list = new List<string>();
			foreach (ElementId elementId in ExternalFileUtils.GetAllExternalFileReferences(doc))
			{
				if (hydocument.GetElement(elementId).IsExternalFileReference())
				{
					ExternalFileReference externalFileReference = hydocument.GetElement(elementId).GetExternalFileReference();
					if (1 == (int)externalFileReference.ExternalFileReferenceType)
					{
						list.Add(ModelPathUtils.ConvertModelPathToUserVisiblePath(externalFileReference.GetAbsolutePath()));
					}
				}
			}
			return list;
		}

		public static bool SetLinkRoomBoundary(Autodesk.Revit.DB.Document doc)
		{
			YJKDocument hydocument = new YJKDocument(doc);
			bool result = false;
			foreach (Element element in YJKElementFilter.GetElementsOfType(doc, typeof(Instance), BuiltInCategory.OST_RvtLinks))
			{
				Instance instance = element as Instance;
				if (instance == null)
				{
					break;
				}
				(hydocument.GetElement(instance.GetTypeId()) as RevitLinkType).get_Parameter(BuiltInParameter.WALL_ATTR_ROOM_BOUNDING).Set(1);
			}
			return result;
		}

		public static void AddWallThickness(Autodesk.Revit.DB.Document doc, WallType wallType, double dWidth)
		{
			Transaction transaction = new Transaction(doc, "修改保温层厚度");
			try
			{
				transaction.Start();
				if (dWidth < 5.0)
				{
					dWidth = 5.0;
				}
				CompoundStructure compoundStructure = wallType.GetCompoundStructure();
				bool flag = false;
				IList<CompoundStructureLayer> layers = compoundStructure.GetLayers();
				foreach (CompoundStructureLayer compoundStructureLayer in layers)
				{
					if ((int)compoundStructureLayer.Function == 3)
					{
						flag = true;
						compoundStructureLayer.Width += dWidth / 304.8;
					}
				}
				if (!flag)
				{
					CompoundStructureLayer compoundStructureLayer2 = new CompoundStructureLayer();
					compoundStructureLayer2.Function = 3;
					FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc);
					filteredElementCollector.OfClass(typeof(Material));
					FilteredElementIterator elementIterator = filteredElementCollector.GetElementIterator();
					elementIterator.Reset();
					while (elementIterator.MoveNext())
					{
						Element element = elementIterator.Current;
						Material material = element as Material;
						if (material.Name.Contains("隔热层"))
						{
							compoundStructureLayer2.MaterialId = material.Id;
							break;
						}
					}
					compoundStructureLayer2.Width = dWidth / 304.8;
					layers.Insert(0, compoundStructureLayer2);
				}
				compoundStructure.SetLayers(layers);
				wallType.SetCompoundStructure(compoundStructure);
				transaction.Commit();
			}
			catch (Exception ex)
			{
				transaction.RollBack();
				throw ex;
			}
		}

		public static void SetWallLayerThick(WallType wallType, double layerThick, FilteredElementIterator materialFEI)
		{
			if (layerThick < 5.0)
			{
				layerThick = 5.0;
			}
			try
			{
				CompoundStructure compoundStructure = wallType.GetCompoundStructure();
				bool flag = false;
				IList<CompoundStructureLayer> layers = compoundStructure.GetLayers();
				foreach (CompoundStructureLayer compoundStructureLayer in layers)
				{
					if ((int)compoundStructureLayer.Function == 3)
					{
						flag = true;
						compoundStructureLayer.Width += layerThick / 304.8;
					}
				}
				if (!flag)
				{
					CompoundStructureLayer compoundStructureLayer2 = new CompoundStructureLayer();
					compoundStructureLayer2.Function = 3;
					materialFEI.Reset();
					while (materialFEI.MoveNext())
					{
						Element element = materialFEI.Current;
						Material material = element as Material;
						if (material.Name.Contains("泡沫体"))
						{
							compoundStructureLayer2.MaterialId = material.Id;
							break;
						}
					}
					compoundStructureLayer2.Width = layerThick / 304.8;
					layers.Insert(0, compoundStructureLayer2);
				}
				compoundStructure.SetLayers(layers);
				wallType.SetCompoundStructure(compoundStructure);
			}
			catch (Exception)
			{
				throw;
			}
		}

		public static FilteredElementIterator GetAllMaterial(Autodesk.Revit.DB.Document doc)
		{
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc);
			filteredElementCollector.OfClass(typeof(Material));
			return filteredElementCollector.GetElementIterator();
		}

		public static List<double> GetWTLayerThick(WallType wType)
		{
			List<double> list = new List<double>();
			foreach (CompoundStructureLayer compoundStructureLayer in wType.GetCompoundStructure().GetLayers())
			{
				list.Add(compoundStructureLayer.Width * 304.8);
			}
			return list;
		}

		public static string GetConnectorSharpName(Connector conn)
		{
			string result = "";
			if (conn.Shape == ConnectorSharp.Rect || conn.Shape == 1)
			{
				result = "矩形";
			}
			else if (conn.Shape == ConnectorSharp.Round || conn.Shape == null)
			{
				result = "圆形";
			}
			else if (conn.Shape == ConnectorSharp.Oval || conn.Shape == 2)
			{
				result = "椭圆形";
			}
			else if (conn.Shape == ConnectorSharp.Invalid || conn.Shape == -1)
			{
				result = "未定义";
			}
			return result;
		}

		public static int GetViewPlanScale(Autodesk.Revit.DB.Document doc)
		{
			int result = -1;
			if (doc.ActiveView is ViewPlan)
			{
				result = (doc.ActiveView as ViewPlan).get_Parameter(BuiltInParameter.VIEW_SCALE).AsInteger();
			}
			else if (doc.ActiveView is View3D)
			{
				result = (doc.ActiveView as View3D).get_Parameter(BuiltInParameter.VIEW_SCALE).AsInteger();
			}
			return result;
		}

		public static bool CheckReferencePlaneName(Autodesk.Revit.DB.Document doc, string name)
		{
			foreach (Element element in ((IEnumerable<Element>)YJKElementFilter.GetElementByCategory(doc, BuiltInCategory.OST_CLines)))
			{
				if (element is ReferencePlane && (element as ReferencePlane).Name == name)
				{
					return true;
				}
			}
			return false;
		}

		public static List<XYZ> GetLayGridXYZList(IList<Element> elemList, double offSet)
		{
			List<XYZ> list = new List<XYZ>();
			foreach (Element element in elemList)
			{
				if (element.Location is LocationCurve)
				{
					HYCurve hycurve = new HYCurve((element.Location as LocationCurve).Curve);
					foreach (Element element2 in elemList)
					{
						if (element.Id.IntegerValue != element2.Id.IntegerValue && element2.Location is LocationCurve)
						{
							XYZ xyz = hycurve.IntersectionPoint((element2.Location as LocationCurve).Curve);
							if (xyz != null)
							{
								XYZ xyz2 = new XYZ(xyz.X, xyz.Y, offSet);
								if (list.Count < 1)
								{
									list.Add(xyz2);
								}
								else
								{
									bool flag = false;
									foreach (XYZ xyz3 in list)
									{
										if (xyz2.IsAlmostEqualTo(xyz3))
										{
											flag = true;
											break;
										}
									}
									if (!flag)
									{
										list.Add(xyz2);
									}
								}
							}
						}
					}
				}
			}
			return list;
		}

		public static XYZ GetLoctaionPoint(Element elem)
		{
			return (elem.Location as LocationPoint).Point;
		}

		public static int GetFamilyHost(Family family)
		{
			return family.get_Parameter(BuiltInParameter.FAMILY_HOSTING_BEHAVIOR).AsInteger();
		}

		public static int GetFamilyHost(FamilySymbol fs)
		{
			return YJKRevitTools.GetFamilyHost(fs.Family);
		}

		public static int GetFamilyHost(FamilyInstance fi)
		{
			return YJKRevitTools.GetFamilyHost(fi.Symbol);
		}

		public static bool IsBaseOnFace(FamilyInstance fi)
		{
			bool result = false;
			int familyHost = YJKRevitTools.GetFamilyHost(fi);
			if (1 == familyHost || 2 == familyHost)
			{
				result = true;
			}
			return result;
		}

		public static bool IsElementIntersectsElement(Element elem1, Element elem2)
		{
			return new ElementIntersectsElementFilter(elem1).PassesFilter(elem2);
		}

		public static List<PlanarFace> GetFamilyInstaceAllFaces(FamilyInstance fInstance)
		{
			List<PlanarFace> list = new List<PlanarFace>();
			ViewDetailLevel detailLevel = fInstance.Document.ActiveView.DetailLevel;
			Options options = new Options();
			fInstance.Document.ActiveView.DetailLevel = (ViewDetailLevel)3;
			options.View = fInstance.Document.ActiveView;
			options.ComputeReferences = true;
			fInstance.Document.Regenerate();
			IEnumerator<GeometryObject> enumerator = fInstance.get_Geometry(options).GetEnumerator();
			enumerator.Reset();
			while (enumerator.MoveNext())
			{
				GeometryObject geometryObject = enumerator.Current;
				if (geometryObject is GeometryInstance)
				{
					foreach (GeometryObject geometryObject2 in (geometryObject as GeometryInstance).GetInstanceGeometry())
					{
						if (geometryObject2 is Solid)
						{
							Solid solid = geometryObject2 as Solid;
							if (!(solid == null))
							{
								foreach (object obj in solid.Faces)
								{
									PlanarFace item = ((Face)obj) as PlanarFace;
									list.Add(item);
								}
							}
						}
					}
				}
			}
			fInstance.Document.ActiveView.DetailLevel = detailLevel;
			return list;
		}

		public static Line getDuctOrPipeLine(Duct duct)
		{
			XYZ hyendPoint = (duct.Location as LocationCurve).Curve.GetEndPoint(0);
			XYZ hyendPoint2 = (duct.Location as LocationCurve).Curve.GetEndPoint(1);
			return YJKLineEx.YJKGetBound(hyendPoint, hyendPoint2);
		}

		public static Line getDuctOrPipeLine(Pipe duct)
		{
			XYZ hyendPoint = (duct.Location as LocationCurve).Curve.GetEndPoint(0);
			XYZ hyendPoint2 = (duct.Location as LocationCurve).Curve.GetEndPoint(1);
			return YJKLineEx.YJKGetBound(hyendPoint, hyendPoint2);
		}

		public static Line getIntersectLine(Line line1, Line line2)
		{
			double z = line1.GetEndPoint(0).Z;
			XYZ hyendPoint = line2.GetEndPoint(0);
			XYZ hyendPoint2 = line2.GetEndPoint(1);
			XYZ startPoint = new XYZ(hyendPoint.X, hyendPoint.Y, z);
			XYZ endPoint = new XYZ(hyendPoint2.X, hyendPoint2.Y, z);
			return YJKLineEx.YJKGetBound(startPoint, endPoint);
		}

		public static bool IsPlumbVector(XYZ vector, XYZ point1, XYZ point2)
		{
			bool result = false;
			XYZ xyz = (point1 - point2).Normalize();
			if (Math.Abs(vector.DotProduct(xyz)) < 0.0001)
			{
				result = true;
			}
			return result;
		}

		public static XYZ GetConnectorDirectionPoint(Connector connector, double distance)
		{
			XYZ result = null;
			if (connector != null)
			{
				Transform coordinateSystem = connector.CoordinateSystem;
				result = connector.Origin + distance * coordinateSystem.BasisZ;
			}
			return result;
		}

		public static bool ConnectTwoElement(Element elem1, Pipe elem2)
		{
			bool flag = false;
			List<Connector> elementAllConnector = YJKRevitTools.GetElementAllConnector(elem1);
			List<Connector> connectorAll = YJKRevitTools.GetConnectorAll(elem2);
			foreach (Connector connector in elementAllConnector)
			{
				foreach (Connector connector2 in connectorAll)
				{
					if (connector.Origin.IsAlmostEqualTo(connector2.Origin, 0.01) && connector.CoordinateSystem.BasisZ.IsAlmostEqualTo(-connector2.CoordinateSystem.BasisZ, 0.01) && !connector.IsConnected && !connector2.IsConnected)
					{
						connector.ConnectTo(connector2);
						flag = true;
						break;
					}
				}
				if (flag)
				{
					break;
				}
			}
			return flag;
		}

		public static bool ConnectTwoElement(Connector conn, Pipe elem2)
		{
			bool result = false;
			foreach (Connector connector in YJKRevitTools.GetConnectorAll(elem2))
			{
				if (conn.Origin.IsAlmostEqualTo(connector.Origin) && conn.CoordinateSystem.BasisZ.IsAlmostEqualTo(-connector.CoordinateSystem.BasisZ) && !conn.IsConnected && !connector.IsConnected)
				{
					conn.ConnectTo(connector);
					result = true;
					break;
				}
			}
			return result;
		}

		public static double GetTwoXYVectorAngle(XYZ vector1, XYZ vector2)
		{
			XYZ xyz = new XYZ(vector1.X, vector1.Y, 0.0);
			XYZ xyz2 = new XYZ(vector2.X, vector2.Y, 0.0);
			XYZ xyz3 = xyz.CrossProduct(xyz2).Normalize();
			double result = xyz.AngleTo(xyz2);
			if (!xyz3.IsAlmostEqualTo(XYZ.BasisZ))
			{
				result = Math.PI*2 - xyz.AngleTo(xyz2);
			}
			return result;
		}

		public static double GetTwoVectorAngle(XYZ vector1, XYZ vector2, XYZ direction)
		{
			double result = 0.0;
			XYZ xyz = vector1.CrossProduct(vector2).Normalize();
			if (xyz.IsAlmostEqualTo(direction.Normalize()))
			{
				result = vector1.AngleTo(vector2);
			}
			if (!xyz.IsAlmostEqualTo(direction.Normalize()))
			{
				result = Math.PI*2 - vector1.AngleTo(vector2);
			}
			return result;
		}

		public static double GetAngleOnPlaneTo(XYZ vectorStart, XYZ vectorEnd, XYZ planeNormal)
		{
			return vectorStart.AngleOnPlaneTo(vectorEnd, planeNormal);
		}

		public static bool SetFamilyInstanceDiameter(FamilyInstance fi, double diameter, ref string errormsg)
		{
			bool result = false;
			Parameter parameter = fi.GetParameter("公称半径");
			if (parameter.IsReadOnly)
			{
				parameter = fi.GetParameter("公称直径");
				if (parameter.IsReadOnly)
				{
					errormsg = "族实例的公称直径和公称半径均为只读";
				}
				else
				{
					parameter.Set(NumbericTools.mmToFeet(diameter));
					result = true;
				}
			}
			else
			{
				parameter.Set(NumbericTools.mmToFeet(diameter / 2.0));
				result = true;
			}
			return result;
		}

		public static Level GetLevelClose(XYZ xyz, Autodesk.Revit.DB.Document doc)
		{
			Level result = null;
			List<Element> elementByClass = YJKElementFilter.GetElementByClass(typeof(Level), doc);
			double num = 1000.0;
			foreach (Element element in elementByClass)
			{
				Level level = (Level)element;
				double num2 = Math.Abs(level.Elevation - xyz.Z);
				if (num > num2)
				{
					result = level;
					num = num2;
				}
			}
			return result;
		}

		public static bool IsSameSizeTwoConnector(Connector conn1, Connector conn2)
		{
			bool result = false;
			if (conn1.Shape == conn2.Shape)
			{
				if (conn1.Shape == ConnectorSharp.Round)
				{
					if (Math.Abs(conn1.Radius - conn2.Radius) < 0.001)
					{
						result = true;
					}
				}
				else if (Math.Abs(conn1.Width - conn2.Width) < 0.001 && Math.Abs(conn1.Height - conn2.Height) < 0.001)
				{
					result = true;
				}
			}
			return result;
		}

		public static void SetFamilyInstanceOffSet(Element elem, Level level, double offset)
		{
			Parameter parameter = elem.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM);
			if (parameter != null && level != null)
			{
				parameter.Set(level.Id);
			}
			Parameter parameter2 = elem.GetParameter(BuiltInParameter.RBS_OFFSET_PARAM);
			if (parameter2 != null)
			{
				parameter2.Set(offset);
			}
		}

		public static double CalArea(List<XYZ> points)
		{
			int num = points.Count;
			if (points.First<XYZ>() == points.Last<XYZ>())
			{
				num--;
			}
			if (num < 3)
			{
				return 0.0;
			}
			double num2 = 0.0;
			for (int i = 1; i < num - 1; i++)
			{
				int index = i + 1;
				num2 += (points[i].X - points[0].X) * (points[index].Y - points[0].Y) - (points[index].X - points[0].X) * (points[i].Y - points[0].Y);
			}
			if (Math.Abs(num2) > 0.0)
			{
				return Math.Abs(num2 / 2.0);
			}
			return 0.0;
		}

		public static List<ViewType> ListViewNeed(int model)
		{
			List<ViewType> list = new List<ViewType>();
			list.Add(1);
			list.Add(2);
			if (model == 2)
			{
				list.Add(4);
				list.Add(3);
			}
			return list;
		}

		public static bool ViewCheck(UIDocument uiDoc, List<ViewType> viewTypes)
		{
			Document document = uiDoc.Document;
			bool flag = false;
			foreach (ViewType viewType in viewTypes)
			{
				if (document.ActiveView.ViewType == viewType)
				{
					flag = true;
				}
			}
			if (!flag)
			{
				List<Element> elementByCategory = YJKElementFilter.GetElementByCategory(document, BuiltInCategory.OST_Views);
				List<Autodesk.Revit.DB.View> list = new List<Autodesk.Revit.DB.View>();
				foreach (Element element in elementByCategory)
				{
					foreach (ViewType viewType2 in viewTypes)
					{
						if ((element as Autodesk.Revit.DB.View).ViewType == viewType2 && !(element as Autodesk.Revit.DB.View).IsTemplate)
						{
							list.Add(element as Autodesk.Revit.DB.View);
							break;
						}
					}
				}
				ViewFormSelect viewFormSelect = new ViewFormSelect(list);
				if (viewFormSelect.ShowDialog() != DialogResult.OK || !(viewFormSelect.viewId != null))
				{
					return false;
				}
				uiDoc.ActiveView = (document.GetElementById(viewFormSelect.viewId) as Autodesk.Revit.DB.View);
			}
			return true;
		}

		public static bool Contains(XYZ pt, List<XYZ> lstPts)
		{
			int num = 0;
			if (lstPts.Count < 3)
			{
				return false;
			}
			for (int i = 0; i < lstPts.Count; i++)
			{
				if (i == lstPts.Count - 1)
				{
					double num2 = (lstPts[0].Y - lstPts[i].Y) / (lstPts[0].X - lstPts[i].X);
					bool flag = lstPts[i].X <= pt.X && pt.X < lstPts[0].X;
					bool flag2 = lstPts[0].X <= pt.X && pt.X < lstPts[i].X;
					bool flag3 = pt.Y < num2 * (pt.X - lstPts[i].X) + lstPts[i].Y;
					if ((flag || flag2) && flag3)
					{
						num++;
					}
				}
				else
				{
					double num3 = (lstPts[i + 1].Y - lstPts[i].Y) / (lstPts[i + 1].X - lstPts[i].X);
					bool flag4 = lstPts[i].X <= pt.X && pt.X < lstPts[i + 1].X;
					bool flag5 = lstPts[i + 1].X <= pt.X && pt.X < lstPts[i].X;
					bool flag6 = pt.Y < num3 * (pt.X - lstPts[i].X) + lstPts[i].Y;
					if ((flag4 || flag5) && flag6)
					{
						num++;
					}
				}
			}
			return num % 2 != 0;
		}

		public static XYZ Centroid(Element room)
		{
			CurveArray curveArray = new CurveArray();
			IList<IList<BoundarySegment>> source = null;
			if (room is Room)
			{
				source = (room as Room).GetBoundarySegments(new SpatialElementBoundaryOptions());
			}
			else if (room is Space)
			{
				source = (room as Space).GetBoundarySegments(new SpatialElementBoundaryOptions());
			}
			foreach (Curve curve in source.SelectMany((IList<BoundarySegment> item) => from roomBS in item
			select UnifiedModified.GetBoundarySegmentCurve(roomBS)))
			{
				curveArray.Append(curve);
			}
			XYZ xyz = YJKRevitTools.Centroid(curveArray);
			XYZ point = (room.Location as LocationPoint).Point;
			return new XYZ(xyz.X, xyz.Y, point.Z);
		}

		public static XYZ Centroid(CurveArray curveArray)
		{
			List<XYZ> list = new List<XYZ>();
			foreach (object obj in curveArray)
			{
				IList<XYZ> list2 = ((Curve)obj).Tessellate();
				for (int i = 0; i < list2.Count - 1; i++)
				{
					list.Add(list2[i]);
				}
			}
			double num = 0.0;
			double num2 = 0.0;
			double num3 = 0.0;
			int count = list.Count;
			for (int j = 0; j < count - 1; j++)
			{
				num += (list[j].X * list[j + 1].Y - list[j + 1].X * list[j].Y) / 2.0;
				num2 += (list[j].X * list[j + 1].Y - list[j + 1].X * list[j].Y) * (list[j].X + list[j + 1].X);
				num3 += (list[j].X * list[j + 1].Y - list[j + 1].X * list[j].Y) * (list[j].Y + list[j + 1].Y);
			}
			num += (list[count - 1].X * list[0].Y - list[0].X * list[count - 1].Y) / 2.0;
			num2 += (list[count - 1].X * list[0].Y - list[0].X * list[count - 1].Y) * (list[count - 1].X + list[0].X);
			num3 += (list[count - 1].X * list[0].Y - list[0].X * list[count - 1].Y) * (list[count - 1].Y + list[0].Y);
			num2 /= 6.0 * num;
			num3 /= 6.0 * num;
			return new XYZ(num2, num3, list[0].Z);
		}

		public static List<Element> GetDoorInRoom(Room room)
		{
			return YJKRevitTools.GetDoorsInSpaceOrRoom(room);
		}

		public static List<Element> GetWindowsInRoom(Room room)
		{
			return YJKRevitTools.GetWindowsInSpaceOrRoom(room);
		}

		public static List<Element> GetDoorsAndWindowsInRoom(Room room)
		{
			List<Element> doorInRoom = YJKRevitTools.GetDoorInRoom(room);
			if (doorInRoom != null)
			{
				doorInRoom.AddRange(YJKRevitTools.GetWindowsInRoom(room));
			}
			return doorInRoom;
		}

		public static List<Element> GetWindowsInSpaceOrRoom(Element spaceOrRoom)
		{
			return YJKRevitTools.GetDoorsOrWindowsInSpaceOrRoom(spaceOrRoom, BuiltInCategory.OST_Windows);
		}

		public static List<Element> GetDoorsInSpaceOrRoom(Element spaceOrRoom)
		{
			return YJKRevitTools.GetDoorsOrWindowsInSpaceOrRoom(spaceOrRoom, BuiltInCategory.OST_Doors);
		}

		public static bool BePipeSysClassType(Pipe pipe, MEPSystemClassification mepSysClass)
		{
			bool result = false;
			if (pipe.MEPSystem.GetSystemClass() == mepSysClass)
			{
				result = true;
			}
			return result;
		}

		public static bool BePipeSystemType(Pipe pipe, PipeSystemType mepSysClass)
		{
			bool result = false;
			try
			{
				if ((pipe.MEPSystem as PipingSystem).SystemType == mepSysClass)
				{
					result = true;
				}
			}
			catch
			{
			}
			return result;
		}

		public static List<Element> GetDoorsOrWindowsInSpaceOrRoom(Element spaceOrRoom, BuiltInCategory doorOrwindowBuiltInCategory)
		{
			if (!(spaceOrRoom is Room) && !(spaceOrRoom is Space))
			{
				return null;
			}
			List<Element> list = new List<Element>();
			List<Element> list2 = new List<Element>();
			IEnumerable<IList<BoundarySegment>> boundarySegments = (spaceOrRoom as SpatialElement).GetBoundarySegments(new SpatialElementBoundaryOptions());
			Document doc = spaceOrRoom.Document;
			Func<BoundarySegment, Element> ss9__2= null;
			foreach (IList<BoundarySegment> list3 in boundarySegments)
			{
				List<Element> list4 = list2;
				IEnumerable<BoundarySegment> source = list3;
				Func<BoundarySegment, Element> selector;
				if ((selector = ss9__2) == null)
				{
                    selector = (ss9__2 = ((BoundarySegment segment) => UnifiedModified.GetBoundarySegmentElement(doc, segment)));
				}
				list4.AddRange(source.Select(selector));
			}
			List<Curve> spaceOrRoomBoundaryCurve = YJKRevitTools.GetSpaceOrRoomBoundaryCurve(spaceOrRoom);
			foreach (Element element in list2)
			{
				if (element != null)
				{
					BoundingBoxXYZ boundingBoxXYZ = element.get_BoundingBox(spaceOrRoom.Document.ActiveView);
					BoundingBoxIntersectsFilter boundingBoxIntersectsFilter = new BoundingBoxIntersectsFilter(new Outline(boundingBoxXYZ.Min, boundingBoxXYZ.Max));
					foreach (Element element2 in new FilteredElementCollector(spaceOrRoom.Document).OfCategory(doorOrwindowBuiltInCategory).WherePasses(boundingBoxIntersectsFilter).ToElements())
					{
						if (element2.Location != null)
						{
							double num = element2.get_Parameter(BuiltInParameter.INSTANCE_SILL_HEIGHT_PARAM).AsDouble();
							double num2 = Math.Sqrt(num * num + Math.Pow(0.98425196850393692, 2.0));
							foreach (Curve curve in spaceOrRoomBoundaryCurve)
							{
								XYZ point = (element2.Location as LocationPoint).Point;
								if (new HYCurve(curve).GetProject(point, false).DistanceTo(point) < num2)
								{
									list.Add(element2);
									break;
								}
							}
						}
					}
				}
			}
			return (from d in list
			group d by d.Id into d
			select d.FirstOrDefault<Element>()).ToList<Element>();
		}

		public static List<Element> GetSapceElements(Element spaceOrRoom, BuiltInCategory doorOrwindowBuiltInCategory)
		{
			if (!(spaceOrRoom is Room) && !(spaceOrRoom is Space))
			{
				return null;
			}
			new List<Element>();
			List<Element> list = new List<Element>();
			IEnumerable<IList<BoundarySegment>> boundarySegments = (spaceOrRoom as SpatialElement).GetBoundarySegments(new SpatialElementBoundaryOptions());
			Document doc = spaceOrRoom.Document;
			Func<BoundarySegment, Element> ss9__0;
			foreach (IList<BoundarySegment> list2 in boundarySegments)
			{
				List<Element> list3 = list;
				IEnumerable<BoundarySegment> source = list2;
				Func<BoundarySegment, Element> selector;
				if ((selector = ss9__0) == null)
				{
					selector = (ss9__0 = ((BoundarySegment segment) => UnifiedModified.GetBoundarySegmentElement(doc, segment)));
				}
				list3.AddRange(source.Select(selector));
			}
			List<Curve> spaceOrRoomBoundaryCurve = YJKRevitTools.GetSpaceOrRoomBoundaryCurve(spaceOrRoom);
			List<Wall> list4 = new List<Wall>();
			foreach (Curve curve in spaceOrRoomBoundaryCurve)
			{
				using (List<Wall>.Enumerator enumerator3 = YJKRevitTools.GetBoundaryCurveWalls(curve, spaceOrRoom.Document).GetEnumerator())
				{
					while (enumerator3.MoveNext())
					{
						Wall item = enumerator3.Current;
						if (!(from s in list4
						where s.Id.IntegerValue == item.Id.IntegerValue
						select s).Any<Wall>())
						{
							list4.Add(item);
						}
					}
				}
			}
			List<Element> list5 = new List<Element>();
			foreach (Wall wall in list4)
			{
				list5.AddRange(YJKRevitTools.GetDoorsOrWindowsInSpaceOrRoomByLink(wall, doorOrwindowBuiltInCategory, spaceOrRoomBoundaryCurve));
			}
			return list5;
		}

		private static List<Element> GetDoorsOrWindowsInSpaceOrRoomByLink(Wall wall, BuiltInCategory doorOrwindowBuiltInCategory, List<Curve> curves)
		{
			List<Element> list = new List<Element>();
			BoundingBoxXYZ boundingBoxXYZ = wall.get_BoundingBox(wall.Document.ActiveView);
			BoundingBoxIntersectsFilter boundingBoxIntersectsFilter = new BoundingBoxIntersectsFilter(new Outline(boundingBoxXYZ.Min, boundingBoxXYZ.Max));
			foreach (Element element in new FilteredElementCollector(wall.Document).OfCategory(doorOrwindowBuiltInCategory).WherePasses(boundingBoxIntersectsFilter).ToElements())
			{
				double num = element.get_Parameter(BuiltInParameter.INSTANCE_SILL_HEIGHT_PARAM).AsDouble();
				double num2 = Math.Sqrt(num * num + Math.Pow(0.98425196850393692, 2.0));
				foreach (Curve curve in curves)
				{
					XYZ point = (element.Location as LocationPoint).Point;
					if (new HYCurve(curve).GetProject(point, false).DistanceTo(point) < num2)
					{
						list.Add(element);
						break;
					}
				}
			}
			return list;
		}

		private static List<Wall> GetBoundaryCurveWalls(Curve curve, Autodesk.Revit.DB.Document doc)
		{
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc);
			XYZ endPoint = curve.GetEndPoint(0);
			curve.GetEndPoint(1);
			double num = NumbericTools.mmToFeet(50.0);
			BoundingBoxIntersectsFilter boundingBoxIntersectsFilter = new BoundingBoxIntersectsFilter(new Outline(new XYZ(endPoint.X - num, endPoint.Y - num, endPoint.Z - num), new XYZ(endPoint.X + num, endPoint.Y + num, endPoint.Z + num)));
			List<Wall> list = filteredElementCollector.OfClass(typeof(Wall)).WherePasses(boundingBoxIntersectsFilter).ToElements().Cast<Wall>().ToList<Wall>();
			foreach (LinkedDocument linkedDocument in doc.GetLinkedDocuments())
			{
				List<Wall> collection = new FilteredElementCollector(linkedDocument.Document).OfClass(typeof(Wall)).WherePasses(boundingBoxIntersectsFilter).ToElements().Cast<Wall>().ToList<Wall>();
				list.AddRange(collection);
			}
			return list;
		}

		public static XYZ SetZToZero(XYZ xyz)
		{
			if (xyz == null)
			{
				return null;
			}
			return new XYZ(xyz.X, xyz.Y, 0.0);
		}

		public static XYZ SetZToSpecValue(XYZ xyz, double zValue)
		{
			if (xyz == null)
			{
				return null;
			}
			return new XYZ(xyz.X, xyz.Y, zValue);
		}

		public static YJKViewRange GetFloorHeigh(Autodesk.Revit.DB.Document doc, Autodesk.Revit.DB.View view)
		{
			YJKViewRange hyviewRange = new YJKViewRange();
			YJKViewRange result;
			try
			{
				PlanViewRange viewRange = (view as ViewPlan).GetViewRange();
				ElementId levelId = viewRange.GetLevelId(2);
				ElementId levelId2 = viewRange.GetLevelId(1);
				Level level = doc.GetElementById(levelId) as Level;
				Level level2 = doc.GetElementById(levelId2) as Level;
				if (level == null && level2 == null)
				{
					hyviewRange.height = Math.Abs(viewRange.GetOffset(1));
					hyviewRange.floorM = YJKViewRange.FloorMark.MidFloor;
					result = hyviewRange;
				}
				else if (level != null && level2 == null)
				{
					hyviewRange.floorM = YJKViewRange.FloorMark.TopFloor;
					result = hyviewRange;
				}
				else if (level == null && level2 != null)
				{
					hyviewRange.floorM = YJKViewRange.FloorMark.ButtonFloor;
					result = hyviewRange;
				}
				else
				{
					hyviewRange.floorM = YJKViewRange.FloorMark.MidFloor;
					if (level.Name == level2.Name)
					{
						hyviewRange.height = Math.Abs(viewRange.GetOffset(1));
					}
					else
					{
						hyviewRange.height = Math.Abs(level.Elevation - level2.Elevation);
					}
					result = hyviewRange;
				}
			}
			catch
			{
				result = hyviewRange;
			}
			return result;
		}

		public static string GetSetSanitaryShortName(Autodesk.Revit.DB.Document doc, Element elem)
		{
			string result;
			try
			{
				SetSanitaryData setSanitaryData = YJKRevitTools.GetSetSanitaryData(doc, elem);
				if (setSanitaryData == null)
				{
					result = string.Empty;
				}
				else
				{
					result = setSanitaryData.ShortName;
				}
			}
			catch
			{
				result = string.Empty;
			}
			return result;
		}

		public static SetSanitaryData GetSetSanitaryData(Autodesk.Revit.DB.Document doc, string familyName)
		{
			try
			{
				List<Document> list = new List<Document>();
				list.Add(doc);
				foreach (LinkedDocument linkedDocument in doc.GetLinkedDocuments())
				{
					list.Add(linkedDocument.Document);
				}
				foreach (Autodesk.Revit.DB.Document document in list)
				{
					FilteredElementCollector filteredElementCollector = new FilteredElementCollector(document);
					filteredElementCollector.OfCategory(BuiltInCategory.OST_PlumbingFixtures);
					filteredElementCollector.OfClass(typeof(FamilyInstance));
					foreach (Element element in filteredElementCollector)
					{
						if ((element as FamilyInstance).Symbol.Family.Name.Equals(familyName))
						{
							return YJKRevitTools.GetSetSanitaryData(doc, element);
						}
					}
				}
			}
			catch (Exception)
			{
				return null;
			}
			return null;
		}

		public static void ModifyLineCategory(Autodesk.Revit.DB.Document doc, string newLineStyleName, ElementId LinePatternId, int LineWeight, System.Drawing.Color LineColor)
		{
			Category category = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Lines);
			Category category2;
			if (!category.SubCategories.Contains(newLineStyleName))
			{
				category2 = doc.Settings.Categories.NewSubcategory(category, newLineStyleName);
			}
			else
			{
				category2 = category.SubCategories.get_Item(newLineStyleName);
			}
			if (LineWeight > 0 && LineWeight < 17)
			{
				category2.SetLineWeight(LineWeight, (Autodesk.Revit.DB.GraphicsStyleType)1);
			}
			if (LineColor != null)
			{
				category2.LineColor = LineColor;
			}
		}

		public static void GetLineCategory(Autodesk.Revit.DB.Document doc, string newLineStyleName, ElementId LinePatternId, int LineWeight, System.Drawing.Color LineColor)
		{
			Category category = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Lines);
			Category category2 = doc.Settings.Categories.NewSubcategory(category, newLineStyleName);
			if (LineWeight > 0 && LineWeight < 17)
			{
				category2.SetLineWeight(LineWeight, (Autodesk.Revit.DB.GraphicsStyleType)1);
			}
			if (LineColor != null)
			{
				category2.LineColor = LineColor;
			}
		}

		public static SetSanitaryData GetSetSanitaryData(Autodesk.Revit.DB.Document doc, Element elem)
		{
			SetSanitaryData setSanitaryData = new SetSanitaryData();
			Element element = elem;
			Schema schema;
			Entity entity;
			if (elem.Document.IsLinked)
			{
				schema = YJKRevitTools.GetSchema(null);
				entity = YJKRevitTools.GetEntityData(ref elem, schema, doc);
				if (entity == null || entity.Schema == null)
				{
					schema = YJKRevitTools.GetSchema(YJKRevitTools.HYBathroomPre + (elem as FamilyInstance).Symbol.Family.Name);
					if (schema != null)
					{
						entity = doc.ProjectInformation.GetEntity(schema);
						elem = doc.ProjectInformation;
					}
					if (entity == null || entity.Schema == null)
					{
						elem = element;
						schema = YJKRevitTools.GetSchema(null);
						if (schema == null)
						{
							return null;
						}
						entity = elem.GetEntity(schema);
					}
				}
			}
			else
			{
				schema = Schema.Lookup(YJKRevitTools.SanitaryGuid);
				entity = YJKRevitTools.GetEntityData(ref elem, schema, doc);
				if (entity == null || entity.Schema == null)
				{
					YJKRevitTools.HYBathroomPre + (elem as FamilyInstance).Symbol.Family.Name;
					schema = Schema.Lookup(YJKRevitTools.SanitaryGuid);
					if (schema != null)
					{
						entity = doc.ProjectInformation.GetEntity(schema);
						elem = doc.ProjectInformation;
					}
				}
			}
			if (entity == null || entity.Schema == null)
			{
				return null;
			}
			SetSanitaryData result;
			try
			{
				setSanitaryData.SanitaryType = YJKRevitTools.GetSanitaryData<string>(schema, elem, SanitaryPara.SanitaryType.ToString(), typeof(string));
				setSanitaryData.HotPointVector = YJKRevitTools.GetSanitaryData<XYZ>(schema, elem, SanitaryPara.HotPointVector.ToString(), typeof(XYZ));
				setSanitaryData.ColdPointVector = YJKRevitTools.GetSanitaryData<XYZ>(schema, elem, SanitaryPara.ColdPointVector.ToString(), typeof(XYZ));
				setSanitaryData.PointOffset = YJKRevitTools.GetSanitaryData<double>(schema, elem, SanitaryPara.PointOffset.ToString(), typeof(double));
				setSanitaryData.ColdOffset = YJKRevitTools.GetSanitaryData<double>(schema, elem, SanitaryPara.ColdOffset.ToString(), typeof(double));
				setSanitaryData.HotOffset = YJKRevitTools.GetSanitaryData<double>(schema, elem, SanitaryPara.HotOffset.ToString(), typeof(double));
				setSanitaryData.Trap = YJKRevitTools.GetSanitaryData<int>(schema, elem, SanitaryPara.Trap.ToString(), typeof(int));
				setSanitaryData.DrainEquivalent = YJKRevitTools.GetSanitaryData<double>(schema, elem, SanitaryPara.DrainEquivalent.ToString(), typeof(double));
				setSanitaryData.DrainFlow = YJKRevitTools.GetSanitaryData<double>(schema, elem, SanitaryPara.DrainFlow.ToString(), typeof(double));
				setSanitaryData.FeedEquivalent = YJKRevitTools.GetSanitaryData<double>(schema, elem, SanitaryPara.FeedEquivalent.ToString(), typeof(double));
				setSanitaryData.FeedFlow = YJKRevitTools.GetSanitaryData<double>(schema, elem, SanitaryPara.FeedFlow.ToString(), typeof(double));
				setSanitaryData.HotAngle = YJKRevitTools.GetSanitaryData<double>(schema, elem, SanitaryPara.HotAngle.ToString(), typeof(double));
				setSanitaryData.ColdAngle = YJKRevitTools.GetSanitaryData<double>(schema, elem, SanitaryPara.ColdAngle.ToString(), typeof(double));
				setSanitaryData.ShortName = YJKRevitTools.GetSanitaryData<string>(schema, elem, SanitaryPara.ShortName.ToString(), typeof(string));
				setSanitaryData.KeyTerminal = YJKRevitTools.GetSanitaryData<string>(schema, elem, SanitaryPara.fieldNew.ToString(), typeof(string));
				setSanitaryData.TerminalLegendName = YJKRevitTools.GetSanitaryData<string>(schema, elem, "New1", typeof(string));
				if (setSanitaryData.HotPointVector != null && !setSanitaryData.HotPointVector.IsAlmostEqualTo(new XYZ(0.0, 0.0, 0.0)) && (int)doc.ActiveView.ViewType != 4 && (int)doc.ActiveView.ViewType != 10)
				{
					setSanitaryData.HotPoint = YJKRevitTools.GetElemPoint(setSanitaryData, setSanitaryData.HotPointVector, setSanitaryData.HotAngle, element, doc);
				}
				if (setSanitaryData.ColdPointVector != null && !setSanitaryData.ColdPointVector.IsAlmostEqualTo(new XYZ(0.0, 0.0, 0.0)) && (int)doc.ActiveView.ViewType != 4 && (int)doc.ActiveView.ViewType != 10)
				{
					setSanitaryData.ColdPoint = YJKRevitTools.GetElemPoint(setSanitaryData, setSanitaryData.ColdPointVector, setSanitaryData.ColdAngle, element, doc);
				}
				result = setSanitaryData;
			}
			catch (Exception)
			{
				MessageBox.Show("Exception");
				result = null;
			}
			return result;
		}

		private static Entity GetEntityData(ref Element elem, Schema sc, Autodesk.Revit.DB.Document doc)
		{
			if (elem == null || sc == null)
			{
				return null;
			}
			if (!elem.Document.IsLinked)
			{
				Entity entity = elem.GetEntity(sc);
				if (entity != null && entity.Schema != null)
				{
					return entity;
				}
			}
			FamilyInstance familyInstance = elem as FamilyInstance;
			if (familyInstance == null)
			{
				return null;
			}
			try
			{
				new List<Element>();
				FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc);
				filteredElementCollector.OfCategory(BuiltInCategory.OST_PlumbingFixtures);
				filteredElementCollector.OfClass(typeof(FamilyInstance));
				foreach (Element element in filteredElementCollector)
				{
					if ((element as FamilyInstance).Symbol.Family.Name.Equals(familyInstance.Symbol.Family.Name))
					{
						Entity entity = element.GetEntity(sc);
						if (entity != null && entity.Schema != null)
						{
							elem = element;
							return entity;
						}
					}
				}
			}
			catch (Exception)
			{
				return null;
			}
			return null;
		}

		private static T GetSanitaryData<T>(Schema schema, Element elem, string fieldName, object obj)
		{
			Entity entity = elem.GetEntity(schema);
			Field field = schema.GetField(fieldName);
			if (field != null)
			{
				return entity.Get<T>(field, 0);
			}
			return (T)((object)obj);
		}

		private static Schema GetSchema(string szSchemaName = null)
		{
			string text = "NewSanitaryPara";
			if (szSchemaName != null)
			{
				text = szSchemaName;
			}
			text = YJKRevitTools.CheckSchemaName(text);
			foreach (Schema schema in Schema.ListSchemas())
			{
				if (schema.SchemaName == text)
				{
					return schema;
				}
			}
			return null;
		}

		public static string CheckSchemaName(string szScName)
		{
			string text = "";
			foreach (char c in szScName)
			{
				if (char.IsLetter(c) || char.IsNumber(c))
				{
					text += c.ToString();
				}
			}
			return text;
		}

		private static XYZ GetElemPoint(SetSanitaryData setSanitaryData, XYZ point, double angle, Element elem, Autodesk.Revit.DB.Document doc)
		{
			XYZ xyz = (elem.Location as LocationPoint).Point;
			if (elem.Document.IsLinked)
			{
				xyz = doc.GetLinkedDocument(elem.Id).GetPointInLinkDocument(xyz);
			}
			point = YJKRevitTools.Rotate(YJKRevitTools.BasisZ(elem), new XYZ(0.0, 0.0, 1.0), -angle) * Math.Sqrt(point.X * point.X + point.Y * point.Y) + xyz;
			point = new XYZ(point.X, point.Y, doc.ActiveView.GenLevel.Elevation + setSanitaryData.PointOffset * 1000.0 / 304.8);
			return point;
		}

		public static XYZ BasisZ(Element elem)
		{
			LocationPoint locationPoint = elem.Location as LocationPoint;
			return YJKRevitTools.Rotate(new XYZ(0.0, 1.0, 0.0), new XYZ(0.0, 0.0, 1.0), locationPoint.Rotation);
		}

		public static XYZ Rotate(XYZ vect, XYZ axis, double angle)
		{
			double x = axis.X;
			double y = axis.Y;
			double z = axis.Z;
			double[,] array = new double[3, 3];
			array[0, 0] = x * x;
			array[0, 1] = x * y;
			array[0, 2] = x * z;
			array[1, 0] = y * x;
			array[1, 1] = y * y;
			array[1, 2] = y * z;
			array[2, 0] = z * x;
			array[2, 1] = z * y;
			array[2, 2] = z * z;
			double[,] array2 = array;
			double[,] array3 = new double[3, 3];
			array3[0, 1] = -z;
			array3[0, 2] = y;
			array3[1, 0] = z;
			array3[1, 2] = -x;
			array3[2, 0] = -y;
			array3[2, 1] = x;
			double[,] array4 = array3;
			double[,] array5 = new double[3, 3];
			array5[0, 0] = 1.0 - array2[0, 0];
			array5[0, 1] = -array2[0, 1];
			array5[0, 2] = -array2[0, 2];
			array5[1, 0] = -array2[1, 0];
			array5[1, 1] = 1.0 - array2[1, 1];
			array5[1, 2] = -array2[1, 2];
			array5[2, 0] = -array2[2, 0];
			array5[2, 1] = -array2[2, 1];
			array5[2, 2] = 1.0 - array2[2, 2];
			double[,] array6 = array5;
			double[,] array7 = new double[3, 3];
			array7[0, 0] = array2[0, 0] + Math.Cos(angle) * array6[0, 0] + Math.Sin(angle) * array4[0, 0];
			array7[0, 1] = array2[0, 1] + Math.Cos(angle) * array6[0, 1] + Math.Sin(angle) * array4[0, 1];
			array7[0, 2] = array2[0, 2] + Math.Cos(angle) * array6[0, 2] + Math.Sin(angle) * array4[0, 2];
			array7[1, 0] = array2[1, 0] + Math.Cos(angle) * array6[1, 0] + Math.Sin(angle) * array4[1, 0];
			array7[1, 1] = array2[1, 1] + Math.Cos(angle) * array6[1, 1] + Math.Sin(angle) * array4[1, 1];
			array7[1, 2] = array2[1, 2] + Math.Cos(angle) * array6[1, 2] + Math.Sin(angle) * array4[1, 2];
			array7[2, 0] = array2[2, 0] + Math.Cos(angle) * array6[2, 0] + Math.Sin(angle) * array4[2, 0];
			array7[2, 1] = array2[2, 1] + Math.Cos(angle) * array6[2, 1] + Math.Sin(angle) * array4[2, 1];
			array7[2, 2] = array2[2, 2] + Math.Cos(angle) * array6[2, 2] + Math.Sin(angle) * array4[2, 2];
			double[,] array8 = array7;
			return new XYZ(array8[0, 0] * vect.X + array8[0, 1] * vect.Y + array8[0, 2] * vect.Z, array8[1, 0] * vect.X + array8[1, 1] * vect.Y + array8[1, 2] * vect.Z, array8[2, 0] * vect.X + array8[2, 1] * vect.Y + array8[2, 2] * vect.Z);
		}

		public static List<Curve> GetSpaceOrRoomBoundaryCurve(Element spaceOrRoom)
		{
			List<Curve> list = new List<Curve>();
			IList<IList<BoundarySegment>> boundarySegments;
			if (spaceOrRoom is Space)
			{
				boundarySegments = (spaceOrRoom as Space).GetBoundarySegments(new SpatialElementBoundaryOptions());
			}
			else
			{
				if (!(spaceOrRoom is Room))
				{
					return null;
				}
				boundarySegments = (spaceOrRoom as Room).GetBoundarySegments(new SpatialElementBoundaryOptions());
			}
			foreach (IList<BoundarySegment> list2 in boundarySegments)
			{
				foreach (BoundarySegment boundarySegment in list2)
				{
					if (boundarySegment != null)
					{
						Curve boundarySegmentCurve = UnifiedModified.GetBoundarySegmentCurve(boundarySegment);
						list.Add(boundarySegmentCurve);
					}
				}
			}
			return list;
		}

		public static List<Element> GetSpaceOrRoomBoundaryWall(Element spaceOrRoom)
		{
			List<Element> list = new List<Element>();
			IList<IList<BoundarySegment>> boundarySegments;
			if (spaceOrRoom is Space)
			{
				boundarySegments = (spaceOrRoom as Space).GetBoundarySegments(new SpatialElementBoundaryOptions());
			}
			else
			{
				if (!(spaceOrRoom is Room))
				{
					return null;
				}
				boundarySegments = (spaceOrRoom as Room).GetBoundarySegments(new SpatialElementBoundaryOptions());
			}
			Document doc = spaceOrRoom.Document;
			Func<BoundarySegment, Element> ss9__0;
			foreach (IList<BoundarySegment> list2 in boundarySegments)
			{
				List<Element> list3 = list;
				IEnumerable<BoundarySegment> source = list2;
				Func<BoundarySegment, Element> selector;
				if ((selector = ss9__0) == null)
				{
					selector = (ss9__0 = ((BoundarySegment segment) => UnifiedModified.GetBoundarySegmentElement(doc, segment)));
				}
				list3.AddRange(source.Select(selector));
			}
			return list;
		}

		public static Guid SanitaryGuid = new Guid("ED9E1F18-DE31-4209-93EA-9161CFC1C31B");

		public static string HYBathroomPre = "HYBathroom";
	}
}
